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
|
2024-01-13 08:15:51 +00:00
|
|
|
, formats
|
2024-02-29 20:09:43 +00:00
|
|
|
, containerRuntimePath ? null
|
|
|
|
, configTemplate ? null
|
2024-01-13 08:15:51 +00:00
|
|
|
, configTemplatePath ? null
|
2023-04-12 12:48:02 +00:00
|
|
|
, libnvidia-container
|
2024-02-29 20:09:43 +00:00
|
|
|
, cudaPackages
|
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
|
|
|
|
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
|
|
|
|
'';
|
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
|
|
|
};
|
|
|
|
|
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 = [
|
|
|
|
cudaPackages.autoAddOpenGLRunpathHook
|
|
|
|
makeWrapper
|
|
|
|
];
|
2021-01-15 22:18:51 +00:00
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
preConfigure = lib.optionalString (containerRuntimePath != null) ''
|
2024-01-13 08:15:51 +00:00
|
|
|
# Ensure the runc symlink isn't broken:
|
|
|
|
if ! readlink --quiet --canonicalize-existing "${isolatedContainerRuntimePath}/runc" ; then
|
|
|
|
echo "${isolatedContainerRuntimePath}/runc: broken symlink" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
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-02-29 20:09:43 +00:00
|
|
|
postInstall = lib.optionalString (containerRuntimePath != null) ''
|
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
|
|
|
|
|
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}
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
# See: https://gitlab.com/nvidia/container-toolkit/container-toolkit/-/blob/03cbf9c6cd26c75afef8a2dd68e0306aace80401/packaging/debian/nvidia-container-toolkit.postinst#L12
|
|
|
|
ln -s $out/bin/nvidia-container-runtime-hook $out/bin/nvidia-container-toolkit
|
2021-01-15 22:18:51 +00:00
|
|
|
|
|
|
|
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 ];
|
|
|
|
};
|
|
|
|
}
|