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
|
2023-04-12 12:48:02 +00:00
|
|
|
, linkFarm
|
|
|
|
, writeShellScript
|
|
|
|
, containerRuntimePath
|
|
|
|
, configTemplate
|
|
|
|
, libnvidia-container
|
2021-01-15 22:18:51 +00:00
|
|
|
}:
|
2023-04-12 12:48:02 +00:00
|
|
|
let
|
|
|
|
isolatedContainerRuntimePath = linkFarm "isolated_container_runtime_path" [
|
|
|
|
{
|
|
|
|
name = "runc";
|
|
|
|
path = containerRuntimePath;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
warnIfXdgConfigHomeIsSet = writeShellScript "warn_if_xdg_config_home_is_set" ''
|
|
|
|
set -eo pipefail
|
2021-01-15 22:18:51 +00:00
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
if [ -n "$XDG_CONFIG_HOME" ]; then
|
|
|
|
echo >&2 "$(tput setaf 3)warning: \$XDG_CONFIG_HOME=$XDG_CONFIG_HOME$(tput sgr 0)"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
in
|
2023-10-09 19:29:22 +00:00
|
|
|
buildGoModule rec {
|
2023-04-12 12:48:02 +00:00
|
|
|
pname = "container-toolkit/container-toolkit";
|
|
|
|
version = "1.9.0";
|
|
|
|
|
|
|
|
src = fetchFromGitLab {
|
|
|
|
owner = "nvidia";
|
2021-01-15 22:18:51 +00:00
|
|
|
repo = pname;
|
|
|
|
rev = "v${version}";
|
2023-10-09 19:29:22 +00:00
|
|
|
hash = "sha256-b4mybNB5FqizFTraByHk5SCsNO66JaISj18nLgLN7IA=";
|
2021-01-15 22:18:51 +00:00
|
|
|
};
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
vendorHash = null;
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
# replace the default hookDefaultFilePath to the $out path
|
|
|
|
substituteInPlace cmd/nvidia-container-runtime/main.go \
|
|
|
|
--replace '/usr/bin/nvidia-container-runtime-hook' '${placeholder "out"}/bin/nvidia-container-runtime-hook'
|
|
|
|
'';
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2021-08-27 14:25:00 +00:00
|
|
|
ldflags = [ "-s" "-w" ];
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
|
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
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
postInstall = ''
|
2023-04-12 12:48:02 +00:00
|
|
|
mkdir -p $out/etc/nvidia-container-runtime
|
|
|
|
|
|
|
|
# nvidia-container-runtime invokes docker-runc or runc if that isn't
|
|
|
|
# available on PATH.
|
|
|
|
#
|
|
|
|
# Also set XDG_CONFIG_HOME if it isn't already to allow overriding
|
|
|
|
# configuration. This in turn allows users to have the nvidia container
|
|
|
|
# runtime enabled for any number of higher level runtimes like docker and
|
|
|
|
# podman, i.e., there's no need to have mutually exclusivity on what high
|
|
|
|
# level runtime can enable the nvidia runtime because each high level
|
|
|
|
# runtime has its own config.toml file.
|
|
|
|
wrapProgram $out/bin/nvidia-container-runtime \
|
|
|
|
--run "${warnIfXdgConfigHomeIsSet}" \
|
|
|
|
--prefix PATH : ${isolatedContainerRuntimePath}:${libnvidia-container}/bin \
|
|
|
|
--set-default XDG_CONFIG_HOME $out/etc
|
|
|
|
|
|
|
|
cp ${configTemplate} $out/etc/nvidia-container-runtime/config.toml
|
|
|
|
|
|
|
|
substituteInPlace $out/etc/nvidia-container-runtime/config.toml \
|
|
|
|
--subst-var-by glibcbin ${lib.getBin glibc}
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
ln -s $out/bin/nvidia-container-{toolkit,runtime-hook}
|
|
|
|
|
|
|
|
wrapProgram $out/bin/nvidia-container-toolkit \
|
2023-04-12 12:48:02 +00:00
|
|
|
--add-flags "-config ${placeholder "out"}/etc/nvidia-container-runtime/config.toml"
|
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 ];
|
|
|
|
};
|
|
|
|
}
|