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
112 cd "$sourceRoot/subprojects"
113 ${lib.optionalString finalAttrs.finalPackage.doCheck ''
114 cp -R --no-preserve=mode,ownership ${cmocka.src} cmocka
116 cp -R --no-preserve=mode,ownership ${implot.src} implot-${implot.version}
117 cp -R --no-preserve=mode,ownership ${imgui.src} imgui-${imgui.version}
118 cp -R --no-preserve=mode,ownership ${vulkan-headers.src} Vulkan-Headers-${vulkan-headers.version}
123 # Add @libraryPath@ template variable to fix loading the preload
124 # library and @dataPath@ to support overlaying Vulkan apps without
125 # requiring MangoHud to be installed
126 ./preload-nix-workaround.patch
128 # Hard code dependencies. Can't use makeWrapper since the Vulkan
129 # layer can be used without the mangohud executable by setting MANGOHUD=1.
131 src = ./hardcode-dependencies.patch;
133 path = lib.makeBinPath [
148 substituteInPlace bin/mangohud.in \
149 --subst-var-by libraryPath ${lib.makeSearchPath "lib/mangohud" ([
151 ] ++ lib.optionals lowerBitnessSupport [
154 --subst-var-by version "${finalAttrs.version}" \
155 --subst-var-by dataDir ${placeholder "out"}/share
159 unzip ${implot.patch}
161 unzip ${vulkan-headers.patch}
166 "-Dwith_wayland=enabled"
167 "-Duse_system_spdlog=enabled"
168 "-Dtests=${if finalAttrs.finalPackage.doCheck then "enabled" else "disabled"}"
169 ] ++ lib.optionals gamescopeSupport [
171 "-Dmangoapp_layer=true"
175 nativeBuildInputs = [
185 # Only the headers are used from these packages
186 # The corresponding libraries are loaded at runtime from the app's runpath
196 ] ++ lib.optionals gamescopeSupport [
205 nativeCheckInputs = [
209 # Support 32bit Vulkan applications by linking in 32bit Vulkan layers
210 # This is needed for the same reason the 32bit preload workaround is needed.
211 postInstall = lib.optionalString lowerBitnessSupport ''
212 ln -s ${mangohud32}/share/vulkan/implicit_layer.d/MangoHud.x86.json \
213 "$out/share/vulkan/implicit_layer.d"
215 ${lib.optionalString gamescopeSupport ''
216 ln -s ${mangohud32}/share/vulkan/implicit_layer.d/libMangoApp.x86.json \
217 "$out/share/vulkan/implicit_layer.d"
224 "x86_64-linux" = "x86_64";
225 "i686-linux" = "x86";
227 layerPlatform = archMap."${stdenv.hostPlatform.system}" or null;
228 # We need to give the different layers separate names or else the loader
229 # might try the 32-bit one first, fail and not attempt to load the 64-bit
230 # layer under the same name.
232 lib.optionalString (layerPlatform != null) ''
233 substituteInPlace $out/share/vulkan/implicit_layer.d/MangoHud.${layerPlatform}.json \
234 --replace "VK_LAYER_MANGOHUD_overlay" "VK_LAYER_MANGOHUD_overlay_${toString stdenv.hostPlatform.parsed.cpu.bits}"
236 # Add OpenGL driver and libXNVCtrl paths to RUNPATH to support NVIDIA cards
237 addDriverRunpath "$out/lib/mangohud/libMangoHud.so"
238 patchelf --add-rpath ${libXNVCtrl}/lib "$out/lib/mangohud/libMangoHud.so"
239 '' + lib.optionalString gamescopeSupport ''
240 addDriverRunpath "$out/bin/mangoapp"
241 '' + lib.optionalString finalAttrs.finalPackage.doCheck ''
242 # libcmocka.so is only used for tests
243 rm "$out/lib/libcmocka.so"
246 passthru.updateScript = nix-update-script { };
249 description = "Vulkan and OpenGL overlay for monitoring FPS, temperatures, CPU/GPU load and more";
250 homepage = "https://github.com/flightlessmango/MangoHud";
251 changelog = "https://github.com/flightlessmango/MangoHud/releases/tag/v${finalAttrs.version}";
252 platforms = platforms.linux;
253 license = licenses.mit;
254 maintainers = with maintainers; [ kira-bruneau zeratax ];