2020-11-06 00:33:48 +00:00
|
|
|
{ stdenv
|
|
|
|
, lib
|
2022-05-18 14:49:53 +00:00
|
|
|
, addOpenGLRunpath
|
2020-11-06 00:33:48 +00:00
|
|
|
, fetchFromGitHub
|
2021-02-05 17:12:51 +00:00
|
|
|
, pkg-config
|
2020-11-06 00:33:48 +00:00
|
|
|
, libelf
|
|
|
|
, libcap
|
|
|
|
, libseccomp
|
|
|
|
, rpcsvc-proto
|
|
|
|
, libtirpc
|
2021-01-15 22:18:51 +00:00
|
|
|
, makeWrapper
|
2022-05-18 14:49:53 +00:00
|
|
|
, substituteAll
|
2022-10-30 15:09:59 +00:00
|
|
|
, removeReferencesTo
|
2022-05-18 14:49:53 +00:00
|
|
|
, go
|
2020-11-06 00:33:48 +00:00
|
|
|
}:
|
|
|
|
let
|
2022-05-18 14:49:53 +00:00
|
|
|
modprobeVersion = "495.44";
|
2020-04-24 23:36:52 +00:00
|
|
|
nvidia-modprobe = fetchFromGitHub {
|
|
|
|
owner = "NVIDIA";
|
|
|
|
repo = "nvidia-modprobe";
|
2022-05-18 14:49:53 +00:00
|
|
|
rev = modprobeVersion;
|
|
|
|
sha256 = "sha256-Y3ZOfge/EcmhqI19yWO7UfPqkvY1CHHvFC5l9vYyGuU=";
|
|
|
|
};
|
|
|
|
modprobePatch = substituteAll {
|
|
|
|
src = ./modprobe.patch;
|
|
|
|
inherit modprobeVersion;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2020-11-06 00:33:48 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "libnvidia-container";
|
2022-05-18 14:49:53 +00:00
|
|
|
version = "1.9.0";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "NVIDIA";
|
2021-01-15 22:18:51 +00:00
|
|
|
repo = pname;
|
2020-04-24 23:36:52 +00:00
|
|
|
rev = "v${version}";
|
2022-05-18 14:49:53 +00:00
|
|
|
sha256 = "sha256-7OTawWwjeKU8wIa8I/+aSvAJli4kEua94nJSNyCajpE=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-11-06 00:33:48 +00:00
|
|
|
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
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
# fix bogus struct declaration
|
|
|
|
./inline-c-struct.patch
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
postPatch = ''
|
2020-11-06 00:33:48 +00:00
|
|
|
sed -i \
|
2021-09-18 10:52:07 +00:00
|
|
|
-e 's/^REVISION ?=.*/REVISION = ${src.rev}/' \
|
2020-11-06 00:33:48 +00:00
|
|
|
-e 's/^COMPILER :=.*/COMPILER = $(CC)/' \
|
|
|
|
mk/common.mk
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
mkdir -p deps/src/nvidia-modprobe-${modprobeVersion}
|
|
|
|
cp -r ${nvidia-modprobe}/* deps/src/nvidia-modprobe-${modprobeVersion}
|
2020-04-24 23:36:52 +00:00
|
|
|
chmod -R u+w deps/src
|
2021-01-09 10:05:03 +00:00
|
|
|
pushd deps/src
|
2022-05-18 14:49:53 +00:00
|
|
|
|
|
|
|
patch -p0 < ${modprobePatch}
|
|
|
|
touch nvidia-modprobe-${modprobeVersion}/.download_stamp
|
2021-01-09 10:05:03 +00:00
|
|
|
popd
|
2022-05-18 14:49:53 +00:00
|
|
|
|
|
|
|
# 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'
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
preBuild = ''
|
|
|
|
HOME="$(mktemp -d)"
|
2021-01-15 22:18:51 +00:00
|
|
|
'';
|
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = toString [ "-I${libtirpc.dev}/include/tirpc" ];
|
2020-11-06 00:33:48 +00:00
|
|
|
NIX_LDFLAGS = [ "-L${libtirpc.dev}/lib" "-ltirpc" ];
|
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
nativeBuildInputs = [ pkg-config go rpcsvc-proto makeWrapper removeReferencesTo ];
|
2020-05-03 17:38:23 +00:00
|
|
|
|
2020-11-06 00:33:48 +00:00
|
|
|
buildInputs = [ libelf libcap libseccomp libtirpc ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
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
|
|
|
|
''
|
2022-10-30 15:09:59 +00:00
|
|
|
remove-references-to -t "${go}" $out/lib/libnvidia-container-go.so.1.9.0
|
2022-05-18 14:49:53 +00:00
|
|
|
wrapProgram $out/bin/nvidia-container-cli --prefix LD_LIBRARY_PATH : ${libraryPath}
|
|
|
|
'';
|
2022-10-30 15:09:59 +00:00
|
|
|
disallowedReferences = [ go ];
|
2022-05-18 14:49:53 +00:00
|
|
|
|
2020-11-06 00:33:48 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
homepage = "https://github.com/NVIDIA/libnvidia-container";
|
|
|
|
description = "NVIDIA container runtime library";
|
2021-01-15 22:18:51 +00:00
|
|
|
license = licenses.asl20;
|
2020-04-24 23:36:52 +00:00
|
|
|
platforms = platforms.linux;
|
2021-01-15 22:18:51 +00:00
|
|
|
maintainers = with maintainers; [ cpcloud ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|