3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/tools/graphics/mangohud/default.nix
K900 04be1e4a9f mangohud: use vendored vulkan-headers to fix build
This isn't great but what can you do.
2023-04-13 11:34:44 +03:00

208 lines
5.4 KiB
Nix

{ lib
, stdenv
, fetchFromGitHub
, fetchurl
, substituteAll
, coreutils
, curl
, glxinfo
, gnugrep
, gnused
, xdg-utils
, dbus
, hwdata
, libX11
, mangohud32
, appstream
, glslang
, makeWrapper
, mako
, meson
, ninja
, pkg-config
, unzip
, libXNVCtrl
, wayland
, glew
, glfw
, nlohmann_json
, xorg
, addOpenGLRunpath
, gamescopeSupport ? true # build mangoapp and mangohudctl
}:
let
# Derived from subprojects/imgui.wrap
imgui = rec {
version = "1.81";
src = fetchFromGitHub {
owner = "ocornut";
repo = "imgui";
rev = "refs/tags/v${version}";
sha256 = "sha256-rRkayXk3xz758v6vlMSaUu5fui6NR8Md3njhDB0gJ18=";
};
patch = fetchurl {
url = "https://wrapdb.mesonbuild.com/v2/imgui_${version}-1/get_patch";
sha256 = "sha256-bQC0QmkLalxdj4mDEdqvvOFtNwz2T1MpTDuMXGYeQ18=";
};
};
# Derived from subprojects/spdlog.wrap
#
# NOTE: We only statically link spdlog due to a bug in pressure-vessel:
# https://github.com/ValveSoftware/steam-runtime/issues/511
#
# Once this fix is released upstream, we should switch back to using
# the system provided spdlog
spdlog = rec {
version = "1.8.5";
src = fetchFromGitHub {
owner = "gabime";
repo = "spdlog";
rev = "refs/tags/v${version}";
sha256 = "sha256-D29jvDZQhPscaOHlrzGN1s7/mXlcsovjbqYpXd7OM50=";
};
patch = fetchurl {
url = "https://wrapdb.mesonbuild.com/v2/spdlog_${version}-1/get_patch";
sha256 = "sha256-PDjyddV5KxKGORECWUMp6YsXc3kks0T5gxKrCZKbdL4=";
};
};
# Derived from subprojects/vulkan-headers.wrap
vulkan-headers = rec {
version = "1.2.158";
src = fetchFromGitHub {
owner = "KhronosGroup";
repo = "Vulkan-Headers";
rev = "v${version}";
hash = "sha256-5uyk2nMwV1MjXoa3hK/WUeGLwpINJJEvY16kc5DEaks=";
};
patch = fetchurl {
url = "https://wrapdb.mesonbuild.com/v2/vulkan-headers_${version}-2/get_patch";
hash = "sha256-hgNYz15z9FjNHoj4w4EW0SOrQh1c4uQSnsOOrt2CDhc=";
};
};
in stdenv.mkDerivation rec {
pname = "mangohud";
version = "0.6.8";
src = fetchFromGitHub {
owner = "flightlessmango";
repo = "MangoHud";
rev = "refs/tags/v${version}";
fetchSubmodules = true;
sha256 = "sha256-jfmgN90kViHa7vMOjo2x4bNY2QbLk93uYEvaA4DxYvg=";
};
outputs = [ "out" "doc" "man" ];
# Unpack subproject sources
postUnpack = ''(
cd "$sourceRoot/subprojects"
cp -R --no-preserve=mode,ownership ${imgui.src} imgui-${imgui.version}
cp -R --no-preserve=mode,ownership ${spdlog.src} spdlog-${spdlog.version}
cp -R --no-preserve=mode,ownership ${vulkan-headers.src} Vulkan-Headers-${vulkan-headers.version}
)'';
env.NIX_CFLAGS_COMPILE = "-I${vulkan-headers.src}/include";
patches = [
# 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;
inherit hwdata libX11;
})
] ++ 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 ${spdlog.patch}
unzip ${vulkan-headers.patch}
)'';
mesonFlags = [
"-Dwith_wayland=enabled"
] ++ lib.optionals gamescopeSupport [
"-Dmangoapp_layer=true"
"-Dmangoapp=true"
"-Dmangohudctl=true"
];
nativeBuildInputs = [
appstream
glslang
makeWrapper
mako
meson
ninja
pkg-config
unzip
];
buildInputs = [
dbus
libX11
libXNVCtrl
wayland
] ++ lib.optionals gamescopeSupport [
glew
glfw
nlohmann_json
xorg.libXrandr
];
# Support 32bit Vulkan applications by linking in 32bit Vulkan layer
# This is needed for the same reason the 32bit OpenGL 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"
'';
# Support Nvidia cards by adding OpenGL path and support overlaying
# Vulkan applications without requiring MangoHud to be installed
postFixup = ''
wrapProgram "$out/bin/mangohud" \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ addOpenGLRunpath.driverLink ]} \
--prefix XDG_DATA_DIRS : "$out/share"
'' + lib.optionalString (gamescopeSupport) ''
if [[ -e "$out/bin/mangoapp" ]]; then
wrapProgram "$out/bin/mangoapp" \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ addOpenGLRunpath.driverLink ]} \
--prefix XDG_DATA_DIRS : "$out/share"
fi
'';
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;
maintainers = with maintainers; [ kira-bruneau zeratax ];
};
}