From 272154f2602ac55700c15cf38f84c44a67fb11b0 Mon Sep 17 00:00:00 2001 From: Atemu Date: Sun, 14 May 2023 18:17:29 +0200 Subject: [PATCH 1/2] mangohud: add bitness suffix to layer name The VK loader finds the 32-bit layer first and does not attempt to load the 64-bit layer afterwards; likely because it shares the same name. Simply giving them different names fixes the issue; both layers are tried and the correct one succeeds. A similar patter is employed by obs-vkcapture which continued working after https://github.com/NixOS/nixpkgs/pull/228870. Fixes https://github.com/NixOS/nixpkgs/issues/230978 --- pkgs/tools/graphics/mangohud/default.nix | 26 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/pkgs/tools/graphics/mangohud/default.nix b/pkgs/tools/graphics/mangohud/default.nix index 5b6e5e8e76de..7903155af40d 100644 --- a/pkgs/tools/graphics/mangohud/default.nix +++ b/pkgs/tools/graphics/mangohud/default.nix @@ -194,16 +194,26 @@ stdenv.mkDerivation (finalAttrs: { ''} ''; - postFixup = '' + postFixup = let + archMap = { + "x86_64-linux" = "x86_64"; + "i686-linux" = "x86"; + }; + layerPlatform = archMap."${stdenv.hostPlatform.system}" or null; + # We need to give the different layers separate names or else the loader + # might try the 32-bit one first, fail and not attempt to load the 64-bit + # layer under the same name. + in lib.optionalString (layerPlatform != null) '' + 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}" + '' + '' # Add OpenGL driver path to RUNPATH to support NVIDIA cards addOpenGLRunpath "$out/lib/mangohud/libMangoHud.so" - ${lib.optionalString gamescopeSupport '' - addOpenGLRunpath "$out/bin/mangoapp" - ''} - ${lib.optionalString finalAttrs.doCheck '' - # libcmocka.so is only used for tests - rm "$out/lib/libcmocka.so" - ''} + '' + lib.optionalString gamescopeSupport '' + addOpenGLRunpath "$out/bin/mangoapp" + '' + lib.optionalString finalAttrs.doCheck '' + # libcmocka.so is only used for tests + rm "$out/lib/libcmocka.so" ''; passthru.updateScript = nix-update-script { }; From 7eacc7f5492f39286696e57fa99bb2becf711bd5 Mon Sep 17 00:00:00 2001 From: Atemu Date: Sun, 14 May 2023 18:28:30 +0200 Subject: [PATCH 2/2] mangohud: make lower bitness support configurable This allows the user to disable 32-bit support for closure size reasons or in order to mitigate loader issues like https://github.com/NixOS/nixpkgs/issues/230978. The name is weird because it can't start with a digit :/ --- pkgs/tools/graphics/mangohud/default.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/tools/graphics/mangohud/default.nix b/pkgs/tools/graphics/mangohud/default.nix index 7903155af40d..877123951448 100644 --- a/pkgs/tools/graphics/mangohud/default.nix +++ b/pkgs/tools/graphics/mangohud/default.nix @@ -30,6 +30,7 @@ , glfw , xorg , gamescopeSupport ? true # build mangoapp and mangohudctl +, lowerBitnessSupport ? stdenv.hostPlatform.is64bit # Support 32 bit on 64bit , nix-update-script }: @@ -128,7 +129,7 @@ stdenv.mkDerivation (finalAttrs: { substituteInPlace bin/mangohud.in \ --subst-var-by libraryPath ${lib.makeSearchPath "lib/mangohud" ([ (placeholder "out") - ] ++ lib.optionals (stdenv.hostPlatform.system == "x86_64-linux") [ + ] ++ lib.optionals lowerBitnessSupport [ mangohud32 ])} \ --subst-var-by dataDir ${placeholder "out"}/share @@ -184,7 +185,7 @@ stdenv.mkDerivation (finalAttrs: { # Support 32bit Vulkan applications by linking in 32bit Vulkan layers # This is needed for the same reason the 32bit preload workaround is needed. - postInstall = lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux") '' + postInstall = lib.optionalString lowerBitnessSupport '' ln -s ${mangohud32}/share/vulkan/implicit_layer.d/MangoHud.x86.json \ "$out/share/vulkan/implicit_layer.d"