Unverified Commit b13801b7 authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

mangohud: add option to disable nvidia support and x11Support (#386505)

parents 22aa6ff2 8c3eacc2
Loading
Loading
Loading
Loading
+42 −31
Original line number Diff line number Diff line
@@ -21,19 +21,31 @@
  pkg-config,
  unzip,
  libX11,
  libXNVCtrl,
  wayland,
  libXNVCtrl,
  nlohmann_json,
  spdlog,
  libxkbcommon,
  glew,
  glfw,
  xorg,
  gamescopeSupport ? true, # build mangoapp and mangohudctl
  libXrandr,
  x11Support ? true,
  waylandSupport ? true,
  nvidiaSupport ? true,
  gamescopeSupport ? true,
  mangoappSupport ? gamescopeSupport,
  mangohudctlSupport ? gamescopeSupport,
  lowerBitnessSupport ? stdenv.hostPlatform.isx86_64, # Support 32 bit on 64bit
  nix-update-script,
  libxkbcommon,
}:

assert lib.assertMsg (
  x11Support || waylandSupport
) "either x11Support or waylandSupport should be enabled";

assert lib.assertMsg (nvidiaSupport -> x11Support) "nvidiaSupport requires x11Support";
assert lib.assertMsg (mangoappSupport -> x11Support) "mangoappSupport requires x11Support";

let
  # Derived from subprojects/imgui.wrap
  imgui = rec {
@@ -151,18 +163,18 @@ stdenv.mkDerivation (finalAttrs: {
    )
  '';

  mesonFlags =
    [
      "-Dwith_wayland=enabled"
  mesonFlags = [
    "-Duse_system_spdlog=enabled"
    "-Dtests=disabled" # amdgpu test segfaults in nix sandbox
    ]
    ++ lib.optionals gamescopeSupport [
      "-Dmangoapp=true"
      "-Dmangohudctl=true"
    (lib.mesonEnable "with_x11" x11Support)
    (lib.mesonEnable "with_wayland" waylandSupport)
    (lib.mesonEnable "with_xnvctrl" nvidiaSupport)
    (lib.mesonBool "mangoapp" mangoappSupport)
    (lib.mesonBool "mangohudctl" mangohudctlSupport)
  ];

  nativeBuildInputs = [
  nativeBuildInputs =
    [
      addDriverRunpath
      glslang
      mako
@@ -170,13 +182,12 @@ stdenv.mkDerivation (finalAttrs: {
      ninja
      pkg-config
      unzip

    ]
    # Only the headers are used from these packages
    # The corresponding libraries are loaded at runtime from the app's runpath
    libX11
    libXNVCtrl
    wayland
  ];
    ++ lib.optional x11Support libX11
    ++ lib.optional waylandSupport wayland
    ++ lib.optional nvidiaSupport libXNVCtrl;

  buildInputs =
    [
@@ -184,11 +195,11 @@ stdenv.mkDerivation (finalAttrs: {
      nlohmann_json
      spdlog
    ]
    ++ lib.optionals gamescopeSupport [
    ++ lib.optional (x11Support || waylandSupport) libxkbcommon
    ++ lib.optionals mangoappSupport [
      glew
      glfw
      xorg.libXrandr
      libxkbcommon
      libXrandr
    ];

  doCheck = true;
@@ -219,12 +230,12 @@ stdenv.mkDerivation (finalAttrs: {
      substituteInPlace $out/share/vulkan/implicit_layer.d/MangoHud.${layerPlatform}.json \
        --replace-fail "VK_LAYER_MANGOHUD_overlay" "VK_LAYER_MANGOHUD_overlay_${toString stdenv.hostPlatform.parsed.cpu.bits}"
    ''
    + ''
    + lib.optionalString nvidiaSupport ''
      # Add OpenGL driver and libXNVCtrl paths to RUNPATH to support NVIDIA cards
      addDriverRunpath "$out/lib/mangohud/libMangoHud.so"
      patchelf --add-rpath ${libXNVCtrl}/lib "$out/lib/mangohud/libMangoHud.so"
    ''
    + lib.optionalString gamescopeSupport ''
    + lib.optionalString mangoappSupport ''
      addDriverRunpath "$out/bin/mangoapp"
    '';