2024-10-23 06:41:50 +00:00
|
|
|
{
|
|
|
|
stdenv,
|
|
|
|
lib,
|
|
|
|
addDriverRunpath,
|
|
|
|
fetchFromGitHub,
|
|
|
|
pkg-config,
|
|
|
|
elfutils,
|
|
|
|
libcap,
|
|
|
|
libseccomp,
|
|
|
|
rpcsvc-proto,
|
|
|
|
libtirpc,
|
|
|
|
makeWrapper,
|
|
|
|
substituteAll,
|
|
|
|
removeReferencesTo,
|
|
|
|
replaceVars,
|
|
|
|
go,
|
2020-11-06 00:33:48 +00:00
|
|
|
}:
|
|
|
|
let
|
2024-10-23 06:41:50 +00:00
|
|
|
modprobeVersion = "550.54.14";
|
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;
|
2024-10-23 06:41:50 +00:00
|
|
|
sha256 = "sha256-iBRMkvOXacs/llTtvc/ZC5i/q9gc8lMuUHxMbu8A+Kg=";
|
2022-05-18 14:49:53 +00:00
|
|
|
};
|
|
|
|
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";
|
2024-10-23 06:41:50 +00:00
|
|
|
version = "1.16.2";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "NVIDIA";
|
2024-10-23 06:41:50 +00:00
|
|
|
repo = "libnvidia-container";
|
2020-04-24 23:36:52 +00:00
|
|
|
rev = "v${version}";
|
2024-10-23 06:41:50 +00:00
|
|
|
sha256 = "sha256-hX+2B+0kHiAC2lyo6kwe7DctPLJWgRdbhlc316OO3r8=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-11-06 00:33:48 +00:00
|
|
|
patches = [
|
2024-10-23 06:41:50 +00:00
|
|
|
# Locations of nvidia driver libraries are not resolved via ldconfig which
|
|
|
|
# doesn't get used on NixOS.
|
|
|
|
# TODO: The latter doesn't really apply anymore.
|
|
|
|
# Additional support binaries like nvidia-smi
|
2020-11-06 00:33:48 +00:00
|
|
|
# are not resolved via the environment PATH but via the derivation output
|
|
|
|
# path.
|
2024-10-23 06:41:50 +00:00
|
|
|
(replaceVars ./fix-library-resolving.patch {
|
|
|
|
inherit (addDriverRunpath) driverLink;
|
|
|
|
})
|
2020-11-06 00:33:48 +00:00
|
|
|
|
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
|
|
|
|
2024-10-23 06:41:50 +00:00
|
|
|
sed -i \
|
|
|
|
-e 's/^GIT_TAG ?=.*/GIT_TAG = ${version}/' \
|
|
|
|
-e 's/^GIT_COMMIT ?=.*/GIT_COMMIT = ${src.rev}/' \
|
|
|
|
versions.mk
|
|
|
|
|
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
|
|
|
'';
|
|
|
|
|
2024-10-23 06:41:50 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = toString [ "-I${lib.getInclude libtirpc}/include/tirpc" ];
|
|
|
|
NIX_LDFLAGS = [
|
|
|
|
"-L${lib.getLib libtirpc}/lib"
|
|
|
|
"-ltirpc"
|
|
|
|
];
|
2020-11-06 00:33:48 +00:00
|
|
|
|
2024-10-23 06:41:50 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
|
|
|
go
|
|
|
|
rpcsvc-proto
|
|
|
|
makeWrapper
|
|
|
|
removeReferencesTo
|
|
|
|
];
|
2020-05-03 17:38:23 +00:00
|
|
|
|
2024-10-23 06:41:50 +00:00
|
|
|
buildInputs = [
|
|
|
|
elfutils
|
|
|
|
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
|
2024-07-31 10:19:44 +00:00
|
|
|
inherit (addDriverRunpath) driverLink;
|
2024-10-23 06:41:50 +00:00
|
|
|
libraryPath = lib.makeLibraryPath [
|
|
|
|
"$out"
|
|
|
|
driverLink
|
|
|
|
"${driverLink}-32"
|
|
|
|
];
|
2022-05-18 14:49:53 +00:00
|
|
|
in
|
|
|
|
''
|
2024-10-23 06:41:50 +00:00
|
|
|
remove-references-to -t "${go}" $out/lib/libnvidia-container-go.so.${version}
|
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;
|
2024-01-13 08:15:51 +00:00
|
|
|
mainProgram = "nvidia-container-cli";
|
2021-01-15 22:18:51 +00:00
|
|
|
maintainers = with maintainers; [ cpcloud ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|