about summary refs log tree commit diff
path: root/pkgs/tools/graphics/mangohud
diff options
context:
space:
mode:
authorKira Bruneau <kira.bruneau@pm.me>2023-04-13 22:07:03 +0000
committerKira Bruneau <kira.bruneau@pm.me>2023-04-14 12:10:15 -0400
commit332d775c5337005b669327f7fe90438f2d9b4af2 (patch)
tree0bcde0b23ef318d0b132f24129f54059079849cb /pkgs/tools/graphics/mangohud
parenta98e3adeeb186033883d5d737b07af34ebafd622 (diff)
mangohud: 0.6.8 -> 0.6.9
Diffstat (limited to 'pkgs/tools/graphics/mangohud')
-rw-r--r--pkgs/tools/graphics/mangohud/default.nix75
-rw-r--r--pkgs/tools/graphics/mangohud/hardcode-dependencies.patch10
-rw-r--r--pkgs/tools/graphics/mangohud/opengl32-nix-workaround.patch12
-rw-r--r--pkgs/tools/graphics/mangohud/preload-nix-workaround.patch26
4 files changed, 65 insertions, 58 deletions
diff --git a/pkgs/tools/graphics/mangohud/default.nix b/pkgs/tools/graphics/mangohud/default.nix
index 734f504caad33..c3710c1c6efbe 100644
--- a/pkgs/tools/graphics/mangohud/default.nix
+++ b/pkgs/tools/graphics/mangohud/default.nix
@@ -13,9 +13,7 @@
 , hwdata
 , mangohud32
 , addOpenGLRunpath
-, appstream
 , glslang
-, makeWrapper
 , mako
 , meson
 , ninja
@@ -24,10 +22,10 @@
 , libXNVCtrl
 , wayland
 , libX11
+, nlohmann_json
 , spdlog
 , glew
 , glfw
-, nlohmann_json
 , xorg
 , gamescopeSupport ? true # build mangoapp and mangohudctl
 , nix-update-script
@@ -41,11 +39,11 @@ let
       owner = "ocornut";
       repo = "imgui";
       rev = "refs/tags/v${version}";
-      sha256 = "sha256-rRkayXk3xz758v6vlMSaUu5fui6NR8Md3njhDB0gJ18=";
+      hash = "sha256-rRkayXk3xz758v6vlMSaUu5fui6NR8Md3njhDB0gJ18=";
     };
     patch = fetchurl {
       url = "https://wrapdb.mesonbuild.com/v2/imgui_${version}-1/get_patch";
-      sha256 = "sha256-bQC0QmkLalxdj4mDEdqvvOFtNwz2T1MpTDuMXGYeQ18=";
+      hash = "sha256-bQC0QmkLalxdj4mDEdqvvOFtNwz2T1MpTDuMXGYeQ18=";
     };
   };
 
@@ -66,14 +64,14 @@ let
 in
 stdenv.mkDerivation (finalAttrs: {
   pname = "mangohud";
-  version = "0.6.8";
+  version = "0.6.9";
 
   src = fetchFromGitHub {
     owner = "flightlessmango";
     repo = "MangoHud";
     rev = "refs/tags/v${finalAttrs.version}";
     fetchSubmodules = true;
-    sha256 = "sha256-jfmgN90kViHa7vMOjo2x4bNY2QbLk93uYEvaA4DxYvg=";
+    hash = "sha256-wvidO9LAZwVUZhYYWnelSiP0Q1WTPoCg6pMXsoJBPPg=";
   };
 
   outputs = [ "out" "doc" "man" ];
@@ -85,9 +83,12 @@ stdenv.mkDerivation (finalAttrs: {
     cp -R --no-preserve=mode,ownership ${vulkan-headers.src} Vulkan-Headers-${vulkan-headers.version}
   )'';
 
-  env.NIX_CFLAGS_COMPILE = "-I${vulkan-headers.src}/include";
-
   patches = [
+    # Add @libraryPath@ template variable to fix loading the preload
+    # library and @dataPath@ to support overlaying Vulkan apps without
+    # requiring MangoHud to be installed
+    ./preload-nix-workaround.patch
+
     # Hard code dependencies. Can't use makeWrapper since the Vulkan
     # layer can be used without the mangohud executable by setting MANGOHUD=1.
     (substituteAll {
@@ -105,40 +106,37 @@ stdenv.mkDerivation (finalAttrs: {
       libdbus = dbus.lib;
       inherit hwdata;
     })
-  ] ++ lib.optionals (stdenv.hostPlatform.system == "x86_64-linux") [
-    # Support 32bit OpenGL applications by appending the mangohud32
-    # lib path to LD_LIBRARY_PATH.
-    #
-    # This workaround is necessary since on Nix's build of ld.so, $LIB
-    # always expands to lib even when running an 32bit application.
-    #
-    # See https://github.com/NixOS/nixpkgs/issues/101597.
-    (substituteAll {
-      src = ./opengl32-nix-workaround.patch;
-      inherit mangohud32;
-    })
   ];
 
-  postPatch = ''(
-    cd subprojects
-    unzip ${imgui.patch}
-    unzip ${vulkan-headers.patch}
-  )'';
+  postPatch = ''
+    substituteInPlace bin/mangohud.in \
+      --subst-var-by libraryPath ${lib.makeSearchPath "lib/mangohud" ([
+        (placeholder "out")
+      ] ++ lib.optionals (stdenv.hostPlatform.system == "x86_64-linux") [
+        mangohud32
+      ])} \
+      --subst-var-by dataDir ${placeholder "out"}/share
+
+    (
+      cd subprojects
+      unzip ${imgui.patch}
+      unzip ${vulkan-headers.patch}
+    )
+  '';
 
   mesonFlags = [
     "-Dwith_wayland=enabled"
     "-Duse_system_spdlog=enabled"
+    "-Dtests=disabled" # Tests require AMD GPU
   ] ++ lib.optionals gamescopeSupport [
-    "-Dmangoapp_layer=true"
     "-Dmangoapp=true"
+    "-Dmangoapp_layer=true"
     "-Dmangohudctl=true"
   ];
 
   nativeBuildInputs = [
     addOpenGLRunpath
-    appstream
     glslang
-    makeWrapper
     mako
     meson
     ninja
@@ -154,37 +152,32 @@ stdenv.mkDerivation (finalAttrs: {
 
   buildInputs = [
     dbus
+    nlohmann_json
     spdlog
   ] ++ lib.optionals gamescopeSupport [
     glew
     glfw
-    nlohmann_json
     xorg.libXrandr
   ];
 
   # Support 32bit Vulkan applications by linking in 32bit Vulkan layers
-  # This is needed for the same reason the 32bit OpenGL workaround is needed.
+  # This is needed for the same reason the 32bit preload workaround is needed.
   postInstall = lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux") ''
-    ln -s ${mangohud32}/share/vulkan/implicit_layer.d/MangoHud.json \
-      "$out/share/vulkan/implicit_layer.d/MangoHud.x86.json"
+    ln -s ${mangohud32}/share/vulkan/implicit_layer.d/MangoHud.x86.json \
+      "$out/share/vulkan/implicit_layer.d"
 
     ${lib.optionalString gamescopeSupport ''
-      ln -s ${mangohud32}/share/vulkan/implicit_layer.d/libMangoApp.json \
-        "$out/share/vulkan/implicit_layer.d/libMangoApp.x86.json"
+      ln -s ${mangohud32}/share/vulkan/implicit_layer.d/libMangoApp.x86.json \
+        "$out/share/vulkan/implicit_layer.d"
     ''}
   '';
 
+  # Add OpenGL driver path to RUNPATH to support NVIDIA cards
   postFixup = ''
-    # Add OpenGL driver path to RUNPATH to support NVIDIA cards
     addOpenGLRunpath "$out/lib/mangohud/libMangoHud.so"
     ${lib.optionalString gamescopeSupport ''
       addOpenGLRunpath "$out/bin/mangoapp"
     ''}
-
-    # Prefix XDG_DATA_DIRS to support overlaying Vulkan apps without
-    # requiring MangoHud to be installed
-    wrapProgram "$out/bin/mangohud" \
-      --prefix XDG_DATA_DIRS : "$out/share"
   '';
 
   passthru.updateScript = nix-update-script { };
diff --git a/pkgs/tools/graphics/mangohud/hardcode-dependencies.patch b/pkgs/tools/graphics/mangohud/hardcode-dependencies.patch
index debd33d107849..d2b11673d77f6 100644
--- a/pkgs/tools/graphics/mangohud/hardcode-dependencies.patch
+++ b/pkgs/tools/graphics/mangohud/hardcode-dependencies.patch
@@ -1,5 +1,5 @@
 diff --git a/src/dbus.cpp b/src/dbus.cpp
-index 3b3cccb..1405725 100644
+index 7379af1..4eef3fe 100644
 --- a/src/dbus.cpp
 +++ b/src/dbus.cpp
 @@ -152,7 +152,7 @@ bool dbus_manager::get_media_player_metadata(metadata& meta, std::string name) {
@@ -12,10 +12,10 @@ index 3b3cccb..1405725 100644
          return false;
      }
 diff --git a/src/logging.cpp b/src/logging.cpp
-index 1668226..f0c8df5 100644
+index 046c847..42782be 100644
 --- a/src/logging.cpp
 +++ b/src/logging.cpp
-@@ -24,7 +24,11 @@ string exec(string command) {
+@@ -26,7 +26,11 @@ string exec(string command) {
  #endif
      std::array<char, 128> buffer;
      std::string result;
@@ -28,10 +28,10 @@ index 1668226..f0c8df5 100644
        return "popen failed!";
      }
 diff --git a/src/pci_ids.cpp b/src/pci_ids.cpp
-index feec222..6baa707 100644
+index 002a843..5a6262b 100644
 --- a/src/pci_ids.cpp
 +++ b/src/pci_ids.cpp
-@@ -24,11 +24,9 @@ std::istream& get_uncommented_line(std::istream& is, std::string &line)
+@@ -24,11 +24,9 @@ static std::istream& get_uncommented_line(std::istream& is, std::string &line)
  void parse_pciids()
  {
      std::ifstream file;
diff --git a/pkgs/tools/graphics/mangohud/opengl32-nix-workaround.patch b/pkgs/tools/graphics/mangohud/opengl32-nix-workaround.patch
deleted file mode 100644
index 03af397faee78..0000000000000
--- a/pkgs/tools/graphics/mangohud/opengl32-nix-workaround.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff --git a/bin/mangohud.in b/bin/mangohud.in
-index e13da99..086443c 100755
---- a/bin/mangohud.in
-+++ b/bin/mangohud.in
-@@ -23,6 +23,6 @@ fi
- # figure out whether the 32 or 64 bit version should be used, and will search
- # for it in the correct directory
- LD_PRELOAD="${LD_PRELOAD}${LD_PRELOAD:+:}${MANGOHUD_LIB_NAME}"
--LD_LIBRARY_PATH="${LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}@ld_libdir_mangohud@"
-+LD_LIBRARY_PATH="${LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}@ld_libdir_mangohud@:@mangohud32@/lib/mangohud"
- 
- exec env MANGOHUD=1 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" LD_PRELOAD="${LD_PRELOAD}" "$@"
diff --git a/pkgs/tools/graphics/mangohud/preload-nix-workaround.patch b/pkgs/tools/graphics/mangohud/preload-nix-workaround.patch
new file mode 100644
index 0000000000000..e360d8c1876ad
--- /dev/null
+++ b/pkgs/tools/graphics/mangohud/preload-nix-workaround.patch
@@ -0,0 +1,26 @@
+diff --git a/bin/mangohud.in b/bin/mangohud.in
+index f975224..24936eb 100755
+--- a/bin/mangohud.in
++++ b/bin/mangohud.in
+@@ -8,16 +8,18 @@ if [ "$#" -eq 0 ]; then
+ 	exit 1
+ fi
+ 
+-MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud.so"
++MANGOHUD_LIB_NAME="libMangoHud.so"
+ 
+ if [ "$1" = "--dlsym" ]; then
+ 	MANGOHUD_DLSYM=1
+-	MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
++	MANGOHUD_LIB_NAME="libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
+ 	shift
+ fi
+ 
+ # Preload using the plain filenames of the libs, the dynamic linker will
+ # figure out whether the 32 or 64 bit version should be used
+ LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}${MANGOHUD_LIB_NAME}"
++LD_LIBRARY_PATH="@libraryPath@${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
++XDG_DATA_DIRS="@dataDir@${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"
+ 
+-exec env MANGOHUD=1 LD_PRELOAD="${LD_PRELOAD}" "$@"
++exec env MANGOHUD=1 LD_PRELOAD="${LD_PRELOAD}" LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" XDG_DATA_DIRS="${XDG_DATA_DIRS}" "$@"