2021-01-15 22:18:51 +00:00
|
|
|
{ lib
|
2023-04-12 12:48:02 +00:00
|
|
|
, glibc
|
|
|
|
, fetchFromGitLab
|
2021-01-15 22:18:51 +00:00
|
|
|
, makeWrapper
|
2023-10-09 19:29:22 +00:00
|
|
|
, buildGoModule
|
2024-01-13 08:15:51 +00:00
|
|
|
, formats
|
2024-02-29 20:09:43 +00:00
|
|
|
, configTemplate ? null
|
2024-01-13 08:15:51 +00:00
|
|
|
, configTemplatePath ? null
|
2023-04-12 12:48:02 +00:00
|
|
|
, libnvidia-container
|
2024-04-21 15:54:59 +00:00
|
|
|
, autoAddDriverRunpath
|
2021-01-15 22:18:51 +00:00
|
|
|
}:
|
2024-01-13 08:15:51 +00:00
|
|
|
|
|
|
|
assert configTemplate != null -> (lib.isAttrs configTemplate && configTemplatePath == null);
|
|
|
|
assert configTemplatePath != null -> (lib.isStringLike configTemplatePath && configTemplate == null);
|
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
let
|
2024-01-13 08:15:51 +00:00
|
|
|
configToml = if configTemplatePath != null then configTemplatePath else (formats.toml { }).generate "config.toml" configTemplate;
|
2024-02-29 20:09:43 +00:00
|
|
|
|
|
|
|
# From https://gitlab.com/nvidia/container-toolkit/container-toolkit/-/blob/03cbf9c6cd26c75afef8a2dd68e0306aace80401/Makefile#L54
|
|
|
|
cliVersionPackage = "github.com/NVIDIA/nvidia-container-toolkit/internal/info";
|
2023-04-12 12:48:02 +00:00
|
|
|
in
|
2023-10-09 19:29:22 +00:00
|
|
|
buildGoModule rec {
|
2023-04-12 12:48:02 +00:00
|
|
|
pname = "container-toolkit/container-toolkit";
|
2024-02-29 20:09:43 +00:00
|
|
|
version = "1.15.0-rc.3";
|
2023-04-12 12:48:02 +00:00
|
|
|
|
|
|
|
src = fetchFromGitLab {
|
|
|
|
owner = "nvidia";
|
2021-01-15 22:18:51 +00:00
|
|
|
repo = pname;
|
|
|
|
rev = "v${version}";
|
2024-02-29 20:09:43 +00:00
|
|
|
hash = "sha256-IH2OjaLbcKSGG44aggolAOuJkjk+GaXnnTbrXfZ0lVo=";
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
outputs = [ "out" "tools" ];
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
vendorHash = null;
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
patches = [
|
|
|
|
# This patch causes library lookups to first attempt loading via dlopen
|
|
|
|
# before falling back to the regular symlink location and ldcache location.
|
|
|
|
./0001-Add-dlopen-discoverer.patch
|
|
|
|
];
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
postPatch = ''
|
2024-02-29 20:09:43 +00:00
|
|
|
# Replace the default hookDefaultFilePath to the $out path and override
|
|
|
|
# default ldconfig locations to the one in nixpkgs.
|
|
|
|
|
|
|
|
substituteInPlace internal/config/config.go \
|
|
|
|
--replace '/usr/bin/nvidia-container-runtime-hook' "$out/bin/nvidia-container-runtime-hook" \
|
|
|
|
--replace '/sbin/ldconfig' '${lib.getBin glibc}/sbin/ldconfig'
|
|
|
|
|
|
|
|
substituteInPlace internal/config/config_test.go \
|
|
|
|
--replace '/sbin/ldconfig' '${lib.getBin glibc}/sbin/ldconfig'
|
|
|
|
|
|
|
|
substituteInPlace tools/container/toolkit/toolkit.go \
|
|
|
|
--replace '/sbin/ldconfig' '${lib.getBin glibc}/sbin/ldconfig'
|
|
|
|
|
|
|
|
substituteInPlace cmd/nvidia-ctk/hook/update-ldcache/update-ldcache.go \
|
|
|
|
--replace '/sbin/ldconfig' '${lib.getBin glibc}/sbin/ldconfig'
|
2023-10-09 19:29:22 +00:00
|
|
|
'';
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
# Based on upstream's Makefile:
|
|
|
|
# https://gitlab.com/nvidia/container-toolkit/container-toolkit/-/blob/03cbf9c6cd26c75afef8a2dd68e0306aace80401/Makefile#L64
|
|
|
|
ldflags = [
|
|
|
|
"-extldflags=-Wl,-z,lazy" # May be redunandant, cf. `man ld`: "Lazy binding is the default".
|
|
|
|
"-s" # "disable symbol table"
|
|
|
|
"-w" # "disable DWARF generation"
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
# "-X name=value"
|
|
|
|
"-X"
|
|
|
|
"${cliVersionPackage}.version=${version}"
|
|
|
|
];
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
2024-04-21 15:54:59 +00:00
|
|
|
autoAddDriverRunpath
|
2024-02-29 20:09:43 +00:00
|
|
|
makeWrapper
|
|
|
|
];
|
2021-01-15 22:18:51 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
checkFlags =
|
|
|
|
let
|
|
|
|
skippedTests = [
|
|
|
|
# Disable tests executing nvidia-container-runtime command.
|
|
|
|
"TestGoodInput"
|
|
|
|
"TestDuplicateHook"
|
|
|
|
];
|
|
|
|
in
|
|
|
|
[ "-skip" "${builtins.concatStringsSep "|" skippedTests}" ];
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
postInstall = ''
|
|
|
|
wrapProgram $out/bin/nvidia-container-runtime-hook \
|
|
|
|
--prefix PATH : ${libnvidia-container}/bin
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
mkdir -p $tools/bin
|
|
|
|
mv $out/bin/{containerd,crio,docker,nvidia-toolkit,toolkit} $tools/bin
|
|
|
|
'' + lib.optionalString (configTemplate != null || configTemplatePath != null) ''
|
|
|
|
mkdir -p $out/etc/nvidia-container-runtime
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2024-01-13 08:15:51 +00:00
|
|
|
cp ${configToml} $out/etc/nvidia-container-runtime/config.toml
|
2023-04-12 12:48:02 +00:00
|
|
|
|
|
|
|
substituteInPlace $out/etc/nvidia-container-runtime/config.toml \
|
|
|
|
--subst-var-by glibcbin ${lib.getBin glibc}
|
2021-01-15 22:18:51 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
2023-04-12 12:48:02 +00:00
|
|
|
homepage = "https://gitlab.com/nvidia/container-toolkit/container-toolkit";
|
|
|
|
description = "NVIDIA Container Toolkit";
|
2021-01-15 22:18:51 +00:00
|
|
|
license = licenses.asl20;
|
|
|
|
platforms = platforms.linux;
|
|
|
|
maintainers = with maintainers; [ cpcloud ];
|
|
|
|
};
|
|
|
|
}
|