From c60fcad63c6009671fc2c6352681ca5d04beb2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 3 Mar 2025 00:20:57 +0100 Subject: [PATCH 1/4] mangohud: add option to disable nvidia support --- pkgs/tools/graphics/mangohud/default.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/tools/graphics/mangohud/default.nix b/pkgs/tools/graphics/mangohud/default.nix index 8844acdb11c9..d020b3bb6376 100644 --- a/pkgs/tools/graphics/mangohud/default.nix +++ b/pkgs/tools/graphics/mangohud/default.nix @@ -28,6 +28,7 @@ glew, glfw, xorg, + nvidiaSupport ? true, gamescopeSupport ? true, # build mangoapp and mangohudctl lowerBitnessSupport ? stdenv.hostPlatform.isx86_64, # Support 32 bit on 64bit nix-update-script, @@ -161,6 +162,7 @@ stdenv.mkDerivation (finalAttrs: { "-Dwith_wayland=enabled" "-Duse_system_spdlog=enabled" "-Dtests=disabled" # amdgpu test segfaults in nix sandbox + (lib.mesonEnable "with_xnvctrl" nvidiaSupport) ] ++ lib.optionals gamescopeSupport [ "-Dmangoapp=true" @@ -179,9 +181,8 @@ stdenv.mkDerivation (finalAttrs: { # 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 nvidiaSupport libXNVCtrl; buildInputs = [ @@ -224,7 +225,7 @@ stdenv.mkDerivation (finalAttrs: { substituteInPlace $out/share/vulkan/implicit_layer.d/MangoHud.${layerPlatform}.json \ --replace "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" From 1e41a945431b6918bdff1a869635a0ee8904c937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 3 Mar 2025 22:56:48 +0100 Subject: [PATCH 2/4] mangohud: add option to disable x11 support This avoids the following error (the application works anyway) on wayland only systems: [2025-03-03 22:53:17.287] [MANGOHUD] [error] [loader_x11.cpp:19] Failed to open 64bit libX11.so.6: libX11.so.6: cannot open shared object file: No such file or directory [2025-03-03 22:53:17.287] [MANGOHUD] [error] [shared_x11.cpp:23] X11 loader failed to load --- pkgs/tools/graphics/mangohud/default.nix | 37 ++++++++++++++---------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/pkgs/tools/graphics/mangohud/default.nix b/pkgs/tools/graphics/mangohud/default.nix index d020b3bb6376..ec4fd440f2c8 100644 --- a/pkgs/tools/graphics/mangohud/default.nix +++ b/pkgs/tools/graphics/mangohud/default.nix @@ -25,16 +25,20 @@ wayland, nlohmann_json, spdlog, + libxkbcommon, glew, glfw, xorg, + x11Support ? true, nvidiaSupport ? true, gamescopeSupport ? true, # build mangoapp and mangohudctl lowerBitnessSupport ? stdenv.hostPlatform.isx86_64, # Support 32 bit on 64bit nix-update-script, - libxkbcommon, }: +assert lib.assertMsg (nvidiaSupport -> x11Support) "nvidiaSupport requires x11Support"; +assert lib.assertMsg (gamescopeSupport -> x11Support) "gamescopeSupport requires x11Support"; + let # Derived from subprojects/imgui.wrap imgui = rec { @@ -162,6 +166,7 @@ stdenv.mkDerivation (finalAttrs: { "-Dwith_wayland=enabled" "-Duse_system_spdlog=enabled" "-Dtests=disabled" # amdgpu test segfaults in nix sandbox + (lib.mesonEnable "with_x11" x11Support) (lib.mesonEnable "with_xnvctrl" nvidiaSupport) ] ++ lib.optionals gamescopeSupport [ @@ -169,32 +174,34 @@ stdenv.mkDerivation (finalAttrs: { "-Dmangohudctl=true" ]; - nativeBuildInputs = [ - addDriverRunpath - glslang - mako - meson - ninja - pkg-config - unzip + nativeBuildInputs = + [ + addDriverRunpath + glslang + mako + meson + 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 - wayland - ] ++ lib.optional nvidiaSupport libXNVCtrl; + # Only the headers are used from these packages + # The corresponding libraries are loaded at runtime from the app's runpath + wayland + ] + ++ lib.optional x11Support libX11 + ++ lib.optional nvidiaSupport libXNVCtrl; buildInputs = [ dbus nlohmann_json spdlog + libxkbcommon # required by x11 or wayland support ] ++ lib.optionals gamescopeSupport [ glew glfw xorg.libXrandr - libxkbcommon ]; doCheck = true; From 190a9a09c973fc11fe12f51dd50900a0e354b23f Mon Sep 17 00:00:00 2001 From: Kira Bruneau Date: Thu, 6 Mar 2025 19:49:51 -0500 Subject: [PATCH 3/4] mangohud: add option to disable waylandSupport --- pkgs/tools/graphics/mangohud/default.nix | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkgs/tools/graphics/mangohud/default.nix b/pkgs/tools/graphics/mangohud/default.nix index ec4fd440f2c8..28fd1e6971ef 100644 --- a/pkgs/tools/graphics/mangohud/default.nix +++ b/pkgs/tools/graphics/mangohud/default.nix @@ -21,8 +21,8 @@ pkg-config, unzip, libX11, - libXNVCtrl, wayland, + libXNVCtrl, nlohmann_json, spdlog, libxkbcommon, @@ -30,12 +30,17 @@ glfw, xorg, x11Support ? true, + waylandSupport ? true, nvidiaSupport ? true, gamescopeSupport ? true, # build mangoapp and mangohudctl lowerBitnessSupport ? stdenv.hostPlatform.isx86_64, # Support 32 bit on 64bit nix-update-script, }: +assert lib.assertMsg ( + x11Support || waylandSupport +) "either x11Support or waylandSupport should be enabled"; + assert lib.assertMsg (nvidiaSupport -> x11Support) "nvidiaSupport requires x11Support"; assert lib.assertMsg (gamescopeSupport -> x11Support) "gamescopeSupport requires x11Support"; @@ -163,10 +168,10 @@ stdenv.mkDerivation (finalAttrs: { mesonFlags = [ - "-Dwith_wayland=enabled" "-Duse_system_spdlog=enabled" "-Dtests=disabled" # amdgpu test segfaults in nix sandbox (lib.mesonEnable "with_x11" x11Support) + (lib.mesonEnable "with_wayland" waylandSupport) (lib.mesonEnable "with_xnvctrl" nvidiaSupport) ] ++ lib.optionals gamescopeSupport [ @@ -183,12 +188,11 @@ 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 - wayland ] + # Only the headers are used from these packages + # The corresponding libraries are loaded at runtime from the app's runpath ++ lib.optional x11Support libX11 + ++ lib.optional waylandSupport wayland ++ lib.optional nvidiaSupport libXNVCtrl; buildInputs = @@ -196,8 +200,8 @@ stdenv.mkDerivation (finalAttrs: { dbus nlohmann_json spdlog - libxkbcommon # required by x11 or wayland support ] + ++ lib.optional (x11Support || waylandSupport) libxkbcommon ++ lib.optionals gamescopeSupport [ glew glfw From 8c3eacc220bba912d65de5eabf231f472a66ca22 Mon Sep 17 00:00:00 2001 From: Kira Bruneau Date: Thu, 6 Mar 2025 20:21:36 -0500 Subject: [PATCH 4/4] mangohud: split gamescopeSupport into mangoapp & mangoctl support --- pkgs/tools/graphics/mangohud/default.nix | 35 ++++++++++++------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/pkgs/tools/graphics/mangohud/default.nix b/pkgs/tools/graphics/mangohud/default.nix index 28fd1e6971ef..3b01d01450a7 100644 --- a/pkgs/tools/graphics/mangohud/default.nix +++ b/pkgs/tools/graphics/mangohud/default.nix @@ -28,11 +28,13 @@ libxkbcommon, glew, glfw, - xorg, + libXrandr, x11Support ? true, waylandSupport ? true, nvidiaSupport ? true, - gamescopeSupport ? true, # build mangoapp and mangohudctl + gamescopeSupport ? true, + mangoappSupport ? gamescopeSupport, + mangohudctlSupport ? gamescopeSupport, lowerBitnessSupport ? stdenv.hostPlatform.isx86_64, # Support 32 bit on 64bit nix-update-script, }: @@ -42,7 +44,7 @@ assert lib.assertMsg ( ) "either x11Support or waylandSupport should be enabled"; assert lib.assertMsg (nvidiaSupport -> x11Support) "nvidiaSupport requires x11Support"; -assert lib.assertMsg (gamescopeSupport -> x11Support) "gamescopeSupport requires x11Support"; +assert lib.assertMsg (mangoappSupport -> x11Support) "mangoappSupport requires x11Support"; let # Derived from subprojects/imgui.wrap @@ -166,18 +168,15 @@ stdenv.mkDerivation (finalAttrs: { ) ''; - mesonFlags = - [ - "-Duse_system_spdlog=enabled" - "-Dtests=disabled" # amdgpu test segfaults in nix sandbox - (lib.mesonEnable "with_x11" x11Support) - (lib.mesonEnable "with_wayland" waylandSupport) - (lib.mesonEnable "with_xnvctrl" nvidiaSupport) - ] - ++ lib.optionals gamescopeSupport [ - "-Dmangoapp=true" - "-Dmangohudctl=true" - ]; + mesonFlags = [ + "-Duse_system_spdlog=enabled" + "-Dtests=disabled" # amdgpu test segfaults in nix sandbox + (lib.mesonEnable "with_x11" x11Support) + (lib.mesonEnable "with_wayland" waylandSupport) + (lib.mesonEnable "with_xnvctrl" nvidiaSupport) + (lib.mesonBool "mangoapp" mangoappSupport) + (lib.mesonBool "mangohudctl" mangohudctlSupport) + ]; nativeBuildInputs = [ @@ -202,10 +201,10 @@ stdenv.mkDerivation (finalAttrs: { spdlog ] ++ lib.optional (x11Support || waylandSupport) libxkbcommon - ++ lib.optionals gamescopeSupport [ + ++ lib.optionals mangoappSupport [ glew glfw - xorg.libXrandr + libXrandr ]; doCheck = true; @@ -241,7 +240,7 @@ stdenv.mkDerivation (finalAttrs: { 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" '';