1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
{ stdenv
, lib
, addOpenGLRunpath
, fetchFromGitHub
, pkg-config
, elfutils
, libcap
, libseccomp
, rpcsvc-proto
, libtirpc
, makeWrapper
, substituteAll
, removeReferencesTo
, go
}:
let
modprobeVersion = "495.44";
nvidia-modprobe = fetchFromGitHub {
owner = "NVIDIA";
repo = "nvidia-modprobe";
rev = modprobeVersion;
sha256 = "sha256-Y3ZOfge/EcmhqI19yWO7UfPqkvY1CHHvFC5l9vYyGuU=";
};
modprobePatch = substituteAll {
src = ./modprobe.patch;
inherit modprobeVersion;
};
in
stdenv.mkDerivation rec {
pname = "libnvidia-container";
version = "1.9.0";
src = fetchFromGitHub {
owner = "NVIDIA";
repo = pname;
rev = "v${version}";
sha256 = "sha256-7OTawWwjeKU8wIa8I/+aSvAJli4kEua94nJSNyCajpE=";
};
patches = [
# locations of nvidia-driver libraries are not resolved via ldconfig which
# doesn't get used on NixOS. Additional support binaries like nvidia-smi
# are not resolved via the environment PATH but via the derivation output
# path.
./libnvc-ldconfig-and-path-fixes.patch
# fix bogus struct declaration
./inline-c-struct.patch
];
postPatch = ''
sed -i \
-e 's/^REVISION ?=.*/REVISION = ${src.rev}/' \
-e 's/^COMPILER :=.*/COMPILER = $(CC)/' \
mk/common.mk
mkdir -p deps/src/nvidia-modprobe-${modprobeVersion}
cp -r ${nvidia-modprobe}/* deps/src/nvidia-modprobe-${modprobeVersion}
chmod -R u+w deps/src
pushd deps/src
patch -p0 < ${modprobePatch}
touch nvidia-modprobe-${modprobeVersion}/.download_stamp
popd
# 1. replace DESTDIR=$(DEPS_DIR) with empty strings to prevent copying
# things into deps/src/nix/store
# 2. similarly, remove any paths prefixed with DEPS_DIR
# 3. prevent building static libraries because we don't build static
# libtirpc (for now)
# 4. prevent installation of static libraries because of step 3
# 5. prevent installation of libnvidia-container-go.so twice
sed -i Makefile \
-e 's#DESTDIR=\$(DEPS_DIR)#DESTDIR=""#g' \
-e 's#\$(DEPS_DIR)\$#\$#g' \
-e 's#all: shared static tools#all: shared tools#g' \
-e '/$(INSTALL) -m 644 $(LIB_STATIC) $(DESTDIR)$(libdir)/d' \
-e '/$(INSTALL) -m 755 $(libdir)\/$(LIBGO_SHARED) $(DESTDIR)$(libdir)/d'
'';
enableParallelBuilding = true;
preBuild = ''
HOME="$(mktemp -d)"
'';
env.NIX_CFLAGS_COMPILE = toString [ "-I${libtirpc.dev}/include/tirpc" ];
NIX_LDFLAGS = [ "-L${libtirpc.dev}/lib" "-ltirpc" ];
nativeBuildInputs = [ pkg-config go rpcsvc-proto makeWrapper removeReferencesTo ];
buildInputs = [ elfutils libcap libseccomp libtirpc ];
makeFlags = [
"WITH_LIBELF=yes"
"prefix=$(out)"
# we can't use the WITH_TIRPC=yes flag that exists in the Makefile for the
# same reason we patch out the static library use of libtirpc so we set the
# define in CFLAGS
"CFLAGS=-DWITH_TIRPC"
];
postInstall =
let
inherit (addOpenGLRunpath) driverLink;
libraryPath = lib.makeLibraryPath [ "$out" driverLink "${driverLink}-32" ];
in
''
remove-references-to -t "${go}" $out/lib/libnvidia-container-go.so.1.9.0
wrapProgram $out/bin/nvidia-container-cli --prefix LD_LIBRARY_PATH : ${libraryPath}
'';
disallowedReferences = [ go ];
meta = with lib; {
homepage = "https://github.com/NVIDIA/libnvidia-container";
description = "NVIDIA container runtime library";
license = licenses.asl20;
platforms = platforms.linux;
mainProgram = "nvidia-container-cli";
maintainers = with maintainers; [ cpcloud ];
};
}
|