33 , gamescopeSupport ? true # build mangoapp and mangohudctl
34 , lowerBitnessSupport ? stdenv.hostPlatform.isx86_64 # Support 32 bit on 64bit
40 # Derived from subprojects/cmocka.wrap
42 src = fetchFromGitLab {
45 rev = "59dc0013f9f29fcf212fe4911c78e734263ce24c";
46 hash = "sha256-IbAZOC0Q60PrKlKVWsgg/PFDV0PLb/yy+Iz/4Iziny0=";
50 # Derived from subprojects/implot.wrap
53 src = fetchFromGitHub {
56 rev = "refs/tags/v${version}";
57 hash = "sha256-/wkVsgz3wiUVZBCgRl2iDD6GWb+AoHN+u0aeqHHgem0=";
60 url = "https://wrapdb.mesonbuild.com/v2/implot_${version}-1/get_patch";
61 hash = "sha256-HGsUYgZqVFL6UMHaHdR/7YQfKCMpcsgtd48pYpNlaMc=";
65 # Derived from subprojects/imgui.wrap
68 src = fetchFromGitHub {
71 rev = "refs/tags/v${version}";
72 hash = "sha256-0k9jKrJUrG9piHNFQaBBY3zgNIKM23ZA879NY+MNYTU=";
75 url = "https://wrapdb.mesonbuild.com/v2/imgui_${version}-1/get_patch";
76 hash = "sha256-myEpDFl9dr+NTus/n/oCSxHZ6mxh6R1kjMyQtChD1YQ=";
80 # Derived from subprojects/vulkan-headers.wrap
81 vulkan-headers = rec {
83 src = fetchFromGitHub {
84 owner = "KhronosGroup";
85 repo = "Vulkan-Headers";
86 rev = "refs/tags/v${version}";
87 hash = "sha256-5uyk2nMwV1MjXoa3hK/WUeGLwpINJJEvY16kc5DEaks=";
90 url = "https://wrapdb.mesonbuild.com/v2/vulkan-headers_${version}-2/get_patch";
91 hash = "sha256-hgNYz15z9FjNHoj4w4EW0SOrQh1c4uQSnsOOrt2CDhc=";
95 stdenv.mkDerivation (finalAttrs: {
99 src = fetchFromGitHub {
100 owner = "flightlessmango";
102 rev = "refs/tags/v${finalAttrs.version}";
103 fetchSubmodules = true;
104 hash = "sha256-cj/F/DWUDm2AHTJvHgkKa+KdIrfxPWLzI570Dp4VFhs=";
107 outputs = [ "out" "doc" "man" ];
109 # Unpack subproject sources
111 cd "$sourceRoot/subprojects"
112 ${lib.optionalString finalAttrs.finalPackage.doCheck ''
113 cp -R --no-preserve=mode,ownership ${cmocka.src} cmocka
115 cp -R --no-preserve=mode,ownership ${implot.src} implot-${implot.version}
116 cp -R --no-preserve=mode,ownership ${imgui.src} imgui-${imgui.version}
117 cp -R --no-preserve=mode,ownership ${vulkan-headers.src} Vulkan-Headers-${vulkan-headers.version}
121 # Add @libraryPath@ template variable to fix loading the preload
122 # library and @dataPath@ to support overlaying Vulkan apps without
123 # requiring MangoHud to be installed
124 ./preload-nix-workaround.patch
126 # Hard code dependencies. Can't use makeWrapper since the Vulkan
127 # layer can be used without the mangohud executable by setting MANGOHUD=1.
129 src = ./hardcode-dependencies.patch;
131 path = lib.makeBinPath [
146 substituteInPlace bin/mangohud.in \
147 --subst-var-by libraryPath ${lib.makeSearchPath "lib/mangohud" ([
149 ] ++ lib.optionals lowerBitnessSupport [
152 --subst-var-by version "${finalAttrs.version}" \
153 --subst-var-by dataDir ${placeholder "out"}/share
157 unzip ${implot.patch}
159 unzip ${vulkan-headers.patch}
164 "-Dwith_wayland=enabled"
165 "-Duse_system_spdlog=enabled"
166 "-Dtests=${if finalAttrs.finalPackage.doCheck then "enabled" else "disabled"}"
167 ] ++ lib.optionals gamescopeSupport [
169 "-Dmangoapp_layer=true"
173 nativeBuildInputs = [
183 # Only the headers are used from these packages
184 # The corresponding libraries are loaded at runtime from the app's runpath
194 ] ++ lib.optionals gamescopeSupport [
203 nativeCheckInputs = [
207 # Support 32bit Vulkan applications by linking in 32bit Vulkan layers
208 # This is needed for the same reason the 32bit preload workaround is needed.
209 postInstall = lib.optionalString lowerBitnessSupport ''
210 ln -s ${mangohud32}/share/vulkan/implicit_layer.d/MangoHud.x86.json \
211 "$out/share/vulkan/implicit_layer.d"
213 ${lib.optionalString gamescopeSupport ''
214 ln -s ${mangohud32}/share/vulkan/implicit_layer.d/libMangoApp.x86.json \
215 "$out/share/vulkan/implicit_layer.d"
222 "x86_64-linux" = "x86_64";
223 "i686-linux" = "x86";
225 layerPlatform = archMap."${stdenv.hostPlatform.system}" or null;
226 # We need to give the different layers separate names or else the loader
227 # might try the 32-bit one first, fail and not attempt to load the 64-bit
228 # layer under the same name.
230 lib.optionalString (layerPlatform != null) ''
231 substituteInPlace $out/share/vulkan/implicit_layer.d/MangoHud.${layerPlatform}.json \
232 --replace "VK_LAYER_MANGOHUD_overlay" "VK_LAYER_MANGOHUD_overlay_${toString stdenv.hostPlatform.parsed.cpu.bits}"
234 # Add OpenGL driver and libXNVCtrl paths to RUNPATH to support NVIDIA cards
235 addDriverRunpath "$out/lib/mangohud/libMangoHud.so"
236 patchelf --add-rpath ${libXNVCtrl}/lib "$out/lib/mangohud/libMangoHud.so"
237 '' + lib.optionalString gamescopeSupport ''
238 addDriverRunpath "$out/bin/mangoapp"
239 '' + lib.optionalString finalAttrs.finalPackage.doCheck ''
240 # libcmocka.so is only used for tests
241 rm "$out/lib/libcmocka.so"
244 passthru.updateScript = nix-update-script { };
247 description = "Vulkan and OpenGL overlay for monitoring FPS, temperatures, CPU/GPU load and more";
248 homepage = "https://github.com/flightlessmango/MangoHud";
249 changelog = "https://github.com/flightlessmango/MangoHud/releases/tag/v${finalAttrs.version}";
250 platforms = platforms.linux;
251 license = licenses.mit;
252 maintainers = with maintainers; [ kira-bruneau zeratax ];