2021-05-20 23:08:51 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2023-04-29 16:46:19 +00:00
|
|
|
, fetchFromGitLab
|
2021-05-03 20:48:10 +00:00
|
|
|
, fetchFromGitHub
|
2021-06-28 23:13:55 +00:00
|
|
|
, fetchurl
|
2021-05-20 23:08:51 +00:00
|
|
|
, substituteAll
|
|
|
|
, coreutils
|
|
|
|
, curl
|
|
|
|
, glxinfo
|
|
|
|
, gnugrep
|
|
|
|
, gnused
|
|
|
|
, xdg-utils
|
|
|
|
, dbus
|
|
|
|
, hwdata
|
|
|
|
, mangohud32
|
2024-07-31 10:19:44 +00:00
|
|
|
, addDriverRunpath
|
2022-08-12 12:06:08 +00:00
|
|
|
, appstream
|
2023-10-09 19:29:22 +00:00
|
|
|
, git
|
2021-05-20 23:08:51 +00:00
|
|
|
, glslang
|
2023-03-15 16:39:30 +00:00
|
|
|
, mako
|
2021-05-03 20:48:10 +00:00
|
|
|
, meson
|
|
|
|
, ninja
|
|
|
|
, pkg-config
|
2021-06-28 23:13:55 +00:00
|
|
|
, unzip
|
2021-05-20 23:08:51 +00:00
|
|
|
, libXNVCtrl
|
2021-06-28 23:13:55 +00:00
|
|
|
, wayland
|
2023-04-29 16:46:19 +00:00
|
|
|
, libX11
|
|
|
|
, nlohmann_json
|
|
|
|
, spdlog
|
2022-08-12 12:06:08 +00:00
|
|
|
, glew
|
|
|
|
, glfw
|
|
|
|
, xorg
|
|
|
|
, gamescopeSupport ? true # build mangoapp and mangohudctl
|
2023-10-09 19:29:22 +00:00
|
|
|
, lowerBitnessSupport ? stdenv.hostPlatform.isx86_64 # Support 32 bit on 64bit
|
2023-04-29 16:46:19 +00:00
|
|
|
, nix-update-script
|
2024-06-05 15:53:02 +00:00
|
|
|
, libxkbcommon
|
2021-05-03 20:48:10 +00:00
|
|
|
}:
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
let
|
2023-04-29 16:46:19 +00:00
|
|
|
# Derived from subprojects/cmocka.wrap
|
2023-10-09 19:29:22 +00:00
|
|
|
cmocka = {
|
2023-04-29 16:46:19 +00:00
|
|
|
src = fetchFromGitLab {
|
|
|
|
owner = "cmocka";
|
|
|
|
repo = "cmocka";
|
|
|
|
rev = "59dc0013f9f29fcf212fe4911c78e734263ce24c";
|
|
|
|
hash = "sha256-IbAZOC0Q60PrKlKVWsgg/PFDV0PLb/yy+Iz/4Iziny0=";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
# Derived from subprojects/implot.wrap
|
|
|
|
implot = rec {
|
|
|
|
version = "0.16";
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "epezent";
|
|
|
|
repo = "implot";
|
|
|
|
rev = "refs/tags/v${version}";
|
|
|
|
hash = "sha256-/wkVsgz3wiUVZBCgRl2iDD6GWb+AoHN+u0aeqHHgem0=";
|
|
|
|
};
|
|
|
|
patch = fetchurl {
|
|
|
|
url = "https://wrapdb.mesonbuild.com/v2/implot_${version}-1/get_patch";
|
|
|
|
hash = "sha256-HGsUYgZqVFL6UMHaHdR/7YQfKCMpcsgtd48pYpNlaMc=";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
# Derived from subprojects/imgui.wrap
|
|
|
|
imgui = rec {
|
2024-02-29 20:09:43 +00:00
|
|
|
version = "1.89.9";
|
2021-06-28 23:13:55 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ocornut";
|
|
|
|
repo = "imgui";
|
2022-08-12 12:06:08 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-0k9jKrJUrG9piHNFQaBBY3zgNIKM23ZA879NY+MNYTU=";
|
2021-06-28 23:13:55 +00:00
|
|
|
};
|
|
|
|
patch = fetchurl {
|
|
|
|
url = "https://wrapdb.mesonbuild.com/v2/imgui_${version}-1/get_patch";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-myEpDFl9dr+NTus/n/oCSxHZ6mxh6R1kjMyQtChD1YQ=";
|
2021-06-28 23:13:55 +00:00
|
|
|
};
|
|
|
|
};
|
2022-08-21 13:32:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
# Derived from subprojects/vulkan-headers.wrap
|
|
|
|
vulkan-headers = rec {
|
|
|
|
version = "1.2.158";
|
2022-08-21 13:32:41 +00:00
|
|
|
src = fetchFromGitHub {
|
2023-04-29 16:46:19 +00:00
|
|
|
owner = "KhronosGroup";
|
|
|
|
repo = "Vulkan-Headers";
|
2024-02-29 20:09:43 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2023-04-29 16:46:19 +00:00
|
|
|
hash = "sha256-5uyk2nMwV1MjXoa3hK/WUeGLwpINJJEvY16kc5DEaks=";
|
2022-08-21 13:32:41 +00:00
|
|
|
};
|
|
|
|
patch = fetchurl {
|
2023-04-29 16:46:19 +00:00
|
|
|
url = "https://wrapdb.mesonbuild.com/v2/vulkan-headers_${version}-2/get_patch";
|
|
|
|
hash = "sha256-hgNYz15z9FjNHoj4w4EW0SOrQh1c4uQSnsOOrt2CDhc=";
|
2022-08-21 13:32:41 +00:00
|
|
|
};
|
|
|
|
};
|
2023-04-29 16:46:19 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2021-05-20 23:08:51 +00:00
|
|
|
pname = "mangohud";
|
2024-06-05 15:53:02 +00:00
|
|
|
version = "0.7.2";
|
2021-05-03 20:48:10 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "flightlessmango";
|
|
|
|
repo = "MangoHud";
|
2023-04-29 16:46:19 +00:00
|
|
|
rev = "refs/tags/v${finalAttrs.version}";
|
2021-05-03 20:48:10 +00:00
|
|
|
fetchSubmodules = true;
|
2024-06-05 15:53:02 +00:00
|
|
|
hash = "sha256-cj/F/DWUDm2AHTJvHgkKa+KdIrfxPWLzI570Dp4VFhs=";
|
2021-05-03 20:48:10 +00:00
|
|
|
};
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
outputs = [ "out" "doc" "man" ];
|
2021-05-20 23:08:51 +00:00
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
# Unpack subproject sources
|
|
|
|
postUnpack = ''(
|
|
|
|
cd "$sourceRoot/subprojects"
|
2024-01-02 11:29:13 +00:00
|
|
|
${lib.optionalString finalAttrs.finalPackage.doCheck ''
|
2023-04-29 16:46:19 +00:00
|
|
|
cp -R --no-preserve=mode,ownership ${cmocka.src} cmocka
|
|
|
|
''}
|
2024-02-29 20:09:43 +00:00
|
|
|
cp -R --no-preserve=mode,ownership ${implot.src} implot-${implot.version}
|
2021-06-28 23:13:55 +00:00
|
|
|
cp -R --no-preserve=mode,ownership ${imgui.src} imgui-${imgui.version}
|
2023-04-29 16:46:19 +00:00
|
|
|
cp -R --no-preserve=mode,ownership ${vulkan-headers.src} Vulkan-Headers-${vulkan-headers.version}
|
2021-06-28 23:13:55 +00:00
|
|
|
)'';
|
|
|
|
|
|
|
|
patches = [
|
2023-04-29 16:46:19 +00:00
|
|
|
# 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
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
# Hard code dependencies. Can't use makeWrapper since the Vulkan
|
|
|
|
# layer can be used without the mangohud executable by setting MANGOHUD=1.
|
|
|
|
(substituteAll {
|
|
|
|
src = ./hardcode-dependencies.patch;
|
|
|
|
|
|
|
|
path = lib.makeBinPath [
|
|
|
|
coreutils
|
|
|
|
curl
|
|
|
|
glxinfo
|
|
|
|
gnugrep
|
|
|
|
gnused
|
|
|
|
xdg-utils
|
|
|
|
];
|
|
|
|
|
|
|
|
libdbus = dbus.lib;
|
2023-04-29 16:46:19 +00:00
|
|
|
inherit hwdata;
|
2021-05-03 20:48:10 +00:00
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace bin/mangohud.in \
|
|
|
|
--subst-var-by libraryPath ${lib.makeSearchPath "lib/mangohud" ([
|
|
|
|
(placeholder "out")
|
2023-05-24 13:37:59 +00:00
|
|
|
] ++ lib.optionals lowerBitnessSupport [
|
2023-04-29 16:46:19 +00:00
|
|
|
mangohud32
|
|
|
|
])} \
|
2023-10-09 19:29:22 +00:00
|
|
|
--subst-var-by version "${finalAttrs.version}" \
|
2023-04-29 16:46:19 +00:00
|
|
|
--subst-var-by dataDir ${placeholder "out"}/share
|
|
|
|
|
|
|
|
(
|
|
|
|
cd subprojects
|
2024-02-29 20:09:43 +00:00
|
|
|
unzip ${implot.patch}
|
2023-04-29 16:46:19 +00:00
|
|
|
unzip ${imgui.patch}
|
|
|
|
unzip ${vulkan-headers.patch}
|
|
|
|
)
|
|
|
|
'';
|
2022-08-21 13:32:41 +00:00
|
|
|
|
2021-05-03 20:48:10 +00:00
|
|
|
mesonFlags = [
|
2021-06-28 23:13:55 +00:00
|
|
|
"-Dwith_wayland=enabled"
|
2023-04-29 16:46:19 +00:00
|
|
|
"-Duse_system_spdlog=enabled"
|
2024-01-02 11:29:13 +00:00
|
|
|
"-Dtests=${if finalAttrs.finalPackage.doCheck then "enabled" else "disabled"}"
|
2022-08-12 12:06:08 +00:00
|
|
|
] ++ lib.optionals gamescopeSupport [
|
|
|
|
"-Dmangoapp=true"
|
2023-04-29 16:46:19 +00:00
|
|
|
"-Dmangoapp_layer=true"
|
2022-08-12 12:06:08 +00:00
|
|
|
"-Dmangohudctl=true"
|
2021-05-03 20:48:10 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
2024-07-31 10:19:44 +00:00
|
|
|
addDriverRunpath
|
2023-10-09 19:29:22 +00:00
|
|
|
git
|
2021-05-20 23:08:51 +00:00
|
|
|
glslang
|
2023-03-15 16:39:30 +00:00
|
|
|
mako
|
2021-05-03 20:48:10 +00:00
|
|
|
meson
|
|
|
|
ninja
|
|
|
|
pkg-config
|
2021-06-28 23:13:55 +00:00
|
|
|
unzip
|
2023-04-29 16:46:19 +00:00
|
|
|
|
|
|
|
# Only the headers are used from these packages
|
|
|
|
# The corresponding libraries are loaded at runtime from the app's runpath
|
|
|
|
libXNVCtrl
|
|
|
|
wayland
|
|
|
|
libX11
|
2021-05-03 20:48:10 +00:00
|
|
|
];
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
buildInputs = [
|
|
|
|
dbus
|
2023-04-29 16:46:19 +00:00
|
|
|
nlohmann_json
|
|
|
|
spdlog
|
2022-08-12 12:06:08 +00:00
|
|
|
] ++ lib.optionals gamescopeSupport [
|
|
|
|
glew
|
|
|
|
glfw
|
|
|
|
xorg.libXrandr
|
2024-06-05 15:53:02 +00:00
|
|
|
libxkbcommon
|
2021-05-20 23:08:51 +00:00
|
|
|
];
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
doCheck = true;
|
|
|
|
|
|
|
|
nativeCheckInputs = [
|
|
|
|
appstream
|
|
|
|
];
|
|
|
|
|
|
|
|
# Support 32bit Vulkan applications by linking in 32bit Vulkan layers
|
|
|
|
# This is needed for the same reason the 32bit preload workaround is needed.
|
2023-05-24 13:37:59 +00:00
|
|
|
postInstall = lib.optionalString lowerBitnessSupport ''
|
2023-04-29 16:46:19 +00:00
|
|
|
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.x86.json \
|
|
|
|
"$out/share/vulkan/implicit_layer.d"
|
|
|
|
''}
|
2021-05-20 23:08:51 +00:00
|
|
|
'';
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
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}"
|
|
|
|
'' + ''
|
2024-06-20 14:57:18 +00:00
|
|
|
# Add OpenGL driver and libXNVCtrl paths to RUNPATH to support NVIDIA cards
|
2024-07-31 10:19:44 +00:00
|
|
|
addDriverRunpath "$out/lib/mangohud/libMangoHud.so"
|
2024-06-20 14:57:18 +00:00
|
|
|
patchelf --add-rpath ${libXNVCtrl}/lib "$out/lib/mangohud/libMangoHud.so"
|
2024-02-29 20:09:43 +00:00
|
|
|
'' + lib.optionalString gamescopeSupport ''
|
2024-07-31 10:19:44 +00:00
|
|
|
addDriverRunpath "$out/bin/mangoapp"
|
2024-02-29 20:09:43 +00:00
|
|
|
'' + lib.optionalString finalAttrs.finalPackage.doCheck ''
|
|
|
|
# libcmocka.so is only used for tests
|
|
|
|
rm "$out/lib/libcmocka.so"
|
|
|
|
'';
|
2021-05-03 20:48:10 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
passthru.updateScript = nix-update-script { };
|
|
|
|
|
2021-05-03 20:48:10 +00:00
|
|
|
meta = with lib; {
|
2024-06-20 14:57:18 +00:00
|
|
|
description = "Vulkan and OpenGL overlay for monitoring FPS, temperatures, CPU/GPU load and more";
|
2021-05-03 20:48:10 +00:00
|
|
|
homepage = "https://github.com/flightlessmango/MangoHud";
|
2024-02-29 20:09:43 +00:00
|
|
|
changelog = "https://github.com/flightlessmango/MangoHud/releases/tag/v${finalAttrs.version}";
|
2021-05-03 20:48:10 +00:00
|
|
|
platforms = platforms.linux;
|
|
|
|
license = licenses.mit;
|
2021-05-28 09:39:13 +00:00
|
|
|
maintainers = with maintainers; [ kira-bruneau zeratax ];
|
2021-05-03 20:48:10 +00:00
|
|
|
};
|
2023-04-29 16:46:19 +00:00
|
|
|
})
|