1{ lib
2, callPackage
3, stdenv
4, fetchFromGitHub
5, cmake
6, pkg-config
7, jq
8, glslang
9, libffi
10, libX11
11, libXau
12, libxcb
13, libXdmcp
14, libXrandr
15, spirv-headers
16, vulkan-headers
17, wayland
18}:
19
20let
21 robin-hood-hashing = callPackage ./robin-hood-hashing.nix {};
22
23 # Current VVL version requires a newer spirv-headers than the latest release tag.
24 # This should hopefully not be too common and the override should be removed after
25 # the next SPIRV headers release.
26 # FIXME: if this ever becomes common, figure out a way to pull revisions directly
27 # from upstream known-good.json
28 spirv-headers' = spirv-headers.overrideAttrs(_: {
29 version = "unstable-2023-04-27";
30
31 src = fetchFromGitHub {
32 owner = "KhronosGroup";
33 repo = "SPIRV-Headers";
34 rev = "7f1d2f4158704337aff1f739c8e494afc5716e7e";
35 hash = "sha256-DHOYIZQqP5uWDYdb+vePpMBaQDOCB5Pcg8wPBMF8itk=";
36 };
37
38 postPatch = "";
39 });
40in
41stdenv.mkDerivation rec {
42 pname = "vulkan-validation-layers";
43 version = "1.3.249";
44
45 # If we were to use "dev" here instead of headers, the setupHook would be
46 # placed in that output instead of "out".
47 outputs = ["out" "headers"];
48 outputInclude = "headers";
49
50 src = fetchFromGitHub {
51 owner = "KhronosGroup";
52 repo = "Vulkan-ValidationLayers";
53 rev = "v${version}";
54 hash = "sha256-+Vjy3hzzpC+bFNSEHLsfUaaHMSrMv2G+B8lGjui0fJs=";
55 };
56
57 nativeBuildInputs = [
58 cmake
59 pkg-config
60 jq
61 ];
62
63 buildInputs = [
64 libX11
65 libXau
66 libXdmcp
67 libXrandr
68 libffi
69 libxcb
70 vulkan-headers
71 wayland
72 ];
73
74 cmakeFlags = [
75 "-DGLSLANG_INSTALL_DIR=${glslang}"
76 "-DSPIRV_HEADERS_INSTALL_DIR=${spirv-headers'}"
77 "-DROBIN_HOOD_HASHING_INSTALL_DIR=${robin-hood-hashing}"
78 "-DBUILD_LAYER_SUPPORT_FILES=ON"
79 "-DPKG_CONFIG_EXECUTABLE=${pkg-config}/bin/pkg-config"
80 # Hide dev warnings that are useless for packaging
81 "-Wno-dev"
82 ];
83
84 # Tests require access to vulkan-compatible GPU, which isn't
85 # available in Nix sandbox. Fails with VK_ERROR_INCOMPATIBLE_DRIVER.
86 doCheck = false;
87
88 # Include absolute paths to layer libraries in their associated
89 # layer definition json files.
90 preFixup = ''
91 for f in "$out"/share/vulkan/explicit_layer.d/*.json "$out"/share/vulkan/implicit_layer.d/*.json; do
92 jq <"$f" >tmp.json ".layer.library_path = \"$out/lib/\" + .layer.library_path"
93 mv tmp.json "$f"
94 done
95 '';
96
97 meta = with lib; {
98 description = "The official Khronos Vulkan validation layers";
99 homepage = "https://github.com/KhronosGroup/Vulkan-ValidationLayers";
100 platforms = platforms.linux;
101 license = licenses.asl20;
102 maintainers = [ maintainers.ralith ];
103 };
104}