1{ stdenv
2, lib
3, fetchFromGitHub
4, pkg-config
5, libelf
6, libcap
7, libseccomp
8, rpcsvc-proto
9, libtirpc
10, makeWrapper
11}:
12let
13 modp-ver = "450.57";
14 nvidia-modprobe = fetchFromGitHub {
15 owner = "NVIDIA";
16 repo = "nvidia-modprobe";
17 rev = modp-ver;
18 sha256 = "0r4f6lpbbqqs9932xd2mr7bxn6a3xdalcwq332fc1amrrkgzfyv7";
19 };
20in
21stdenv.mkDerivation rec {
22 pname = "libnvidia-container";
23 version = "1.5.0";
24
25 src = fetchFromGitHub {
26 owner = "NVIDIA";
27 repo = pname;
28 rev = "v${version}";
29 sha256 = "sha256-b9yQ1mEo1EkjXMguV0t98OvFEQO4h76EVu154MsB2II=";
30 };
31
32 patches = [
33 # locations of nvidia-driver libraries are not resolved via ldconfig which
34 # doesn't get used on NixOS. Additional support binaries like nvidia-smi
35 # are not resolved via the environment PATH but via the derivation output
36 # path.
37 ./libnvc-ldconfig-and-path-fixes.patch
38
39 # the libnvidia-container Makefile wants to build and install static
40 # libtirpc libraries; this patch prevents that from happening
41 ./avoid-static-libtirpc-build.patch
42 ];
43
44 makeFlags = [
45 "WITH_LIBELF=yes"
46 "prefix=$(out)"
47 # we can't use the WITH_TIRPC=yes flag that exists in the Makefile for the
48 # same reason we patch out the static library use of libtirpc so we set the
49 # define in CFLAGS
50 "CFLAGS=-DWITH_TIRPC"
51 ];
52
53 postPatch = ''
54 sed -i \
55 -e 's/^REVISION ?=.*/REVISION = ${src.rev}/' \
56 -e 's/^COMPILER :=.*/COMPILER = $(CC)/' \
57 mk/common.mk
58
59 mkdir -p deps/src/nvidia-modprobe-${modp-ver}
60 cp -r ${nvidia-modprobe}/* deps/src/nvidia-modprobe-${modp-ver}
61 chmod -R u+w deps/src
62 pushd deps/src
63 patch -p0 < ${./modprobe.patch}
64 touch nvidia-modprobe-${modp-ver}/.download_stamp
65 popd
66 '';
67
68 postInstall = ''
69 wrapProgram $out/bin/nvidia-container-cli \
70 --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib:/run/opengl-driver-32/lib
71 '';
72
73 NIX_CFLAGS_COMPILE = [ "-I${libtirpc.dev}/include/tirpc" ];
74 NIX_LDFLAGS = [ "-L${libtirpc.dev}/lib" "-ltirpc" ];
75
76 nativeBuildInputs = [ pkg-config rpcsvc-proto makeWrapper ];
77
78 buildInputs = [ libelf libcap libseccomp libtirpc ];
79
80 meta = with lib; {
81 homepage = "https://github.com/NVIDIA/libnvidia-container";
82 description = "NVIDIA container runtime library";
83 license = licenses.asl20;
84 platforms = platforms.linux;
85 maintainers = with maintainers; [ cpcloud ];
86 };
87}