@@ -1,4 +1,12 @@
1−{ stdenv, buildGoPackage, fetchFromGitHub, version, sha256 }:
1+{ lib
2+, buildGoPackage
3+, fetchFromGitHub
4+, version
5+, sha256
6+, nvidiaGpuSupport
7+, patchelf
8+, nvidia_x11
9+}:
210
311buildGoPackage rec {
412 pname = "nomad";
@@ -14,23 +22,33 @@ buildGoPackage rec {
1422 inherit rev sha256;
1523 };
1624
25+ nativeBuildInputs = lib.optionals nvidiaGpuSupport [
26+ patchelf
27+ ];
28+
1729 # ui:
1830 # Nomad release commits include the compiled version of the UI, but the file
1931 # is only included if we build with the ui tag.
20− # nonvidia:
21− # We disable Nvidia GPU scheduling on Linux, as it doesn't work there:
22− # Ref: https://github.com/hashicorp/nomad/issues/5535
23− preBuild = let
24− tags = ["ui"]
25− ++ stdenv.lib.optional stdenv.isLinux "nonvidia";
26− tagsString = stdenv.lib.concatStringsSep " " tags;
27− in ''
28− export buildFlagsArray=(
29− -tags="${tagsString}"
30− )
31− '';
32+ preBuild =
33+ let
34+ tags = [ "ui" ] ++ lib.optional (!nvidiaGpuSupport) "nonvidia";
35+ tagsString = lib.concatStringsSep " " tags;
36+ in
37+ ''
38+ export buildFlagsArray=(
39+ -tags="${tagsString}"
40+ )
41+ '';
42+
43+ # The dependency on NVML isn't explicit. We have to make it so otherwise the
44+ # binary will not know where to look for the relevant symbols.
45+ postFixup = lib.optionalString nvidiaGpuSupport ''
46+ for bin in $out/bin/*; do
47+ patchelf --add-needed "${nvidia_x11}/lib/libnvidia-ml.so" "$bin"
48+ done
49+ '';
3250
33− meta = with stdenv.lib; {
51+ meta = with lib; {
3452 homepage = "https://www.nomadproject.io/";
3553 description = "A Distributed, Highly Available, Datacenter-Aware Scheduler";
3654 platforms = platforms.unix;