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
|
2023-04-29 16:46:19 +00:00
|
|
|
, addOpenGLRunpath
|
2022-08-12 12:06:08 +00:00
|
|
|
, appstream
|
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-05-24 13:37:59 +00:00
|
|
|
, lowerBitnessSupport ? stdenv.hostPlatform.is64bit # Support 32 bit on 64bit
|
2023-04-29 16:46:19 +00:00
|
|
|
, nix-update-script
|
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
|
|
|
|
cmocka = rec {
|
|
|
|
version = "1.81";
|
|
|
|
src = fetchFromGitLab {
|
|
|
|
owner = "cmocka";
|
|
|
|
repo = "cmocka";
|
|
|
|
rev = "59dc0013f9f29fcf212fe4911c78e734263ce24c";
|
|
|
|
hash = "sha256-IbAZOC0Q60PrKlKVWsgg/PFDV0PLb/yy+Iz/4Iziny0=";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
# Derived from subprojects/imgui.wrap
|
|
|
|
imgui = rec {
|
|
|
|
version = "1.81";
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ocornut";
|
|
|
|
repo = "imgui";
|
2022-08-12 12:06:08 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2023-04-29 16:46:19 +00:00
|
|
|
hash = "sha256-rRkayXk3xz758v6vlMSaUu5fui6NR8Md3njhDB0gJ18=";
|
2021-06-28 23:13:55 +00:00
|
|
|
};
|
|
|
|
patch = fetchurl {
|
|
|
|
url = "https://wrapdb.mesonbuild.com/v2/imgui_${version}-1/get_patch";
|
2023-04-29 16:46:19 +00:00
|
|
|
hash = "sha256-bQC0QmkLalxdj4mDEdqvvOFtNwz2T1MpTDuMXGYeQ18=";
|
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";
|
|
|
|
rev = "v${version}";
|
|
|
|
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";
|
2023-04-29 16:46:19 +00:00
|
|
|
version = "0.6.9-1";
|
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;
|
2023-04-29 16:46:19 +00:00
|
|
|
hash = "sha256-AX4m1XZ+yXp74E3slFGyI3CGu2eYU+eXNN2EY+ivdfk=";
|
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"
|
2023-04-29 16:46:19 +00:00
|
|
|
${lib.optionalString finalAttrs.doCheck ''
|
|
|
|
cp -R --no-preserve=mode,ownership ${cmocka.src} cmocka
|
|
|
|
''}
|
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
|
|
|
|
])} \
|
|
|
|
--subst-var-by dataDir ${placeholder "out"}/share
|
|
|
|
|
|
|
|
(
|
|
|
|
cd subprojects
|
|
|
|
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"
|
|
|
|
"-Dtests=${if finalAttrs.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 = [
|
2023-04-29 16:46:19 +00:00
|
|
|
addOpenGLRunpath
|
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
|
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
|
|
|
'';
|
|
|
|
|
2023-05-24 13:37:59 +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}"
|
|
|
|
'' + ''
|
2023-04-29 16:46:19 +00:00
|
|
|
# Add OpenGL driver path to RUNPATH to support NVIDIA cards
|
|
|
|
addOpenGLRunpath "$out/lib/mangohud/libMangoHud.so"
|
2023-05-24 13:37:59 +00:00
|
|
|
'' + lib.optionalString gamescopeSupport ''
|
|
|
|
addOpenGLRunpath "$out/bin/mangoapp"
|
|
|
|
'' + lib.optionalString finalAttrs.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; {
|
|
|
|
description = "A Vulkan and OpenGL overlay for monitoring FPS, temperatures, CPU/GPU load and more";
|
|
|
|
homepage = "https://github.com/flightlessmango/MangoHud";
|
|
|
|
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
|
|
|
})
|