Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib 2, glibc 3, fetchFromGitLab 4, makeWrapper 5, buildGoPackage 6, linkFarm 7, writeShellScript 8, containerRuntimePath 9, configTemplate 10, libnvidia-container 11}: 12let 13 isolatedContainerRuntimePath = linkFarm "isolated_container_runtime_path" [ 14 { 15 name = "runc"; 16 path = containerRuntimePath; 17 } 18 ]; 19 warnIfXdgConfigHomeIsSet = writeShellScript "warn_if_xdg_config_home_is_set" '' 20 set -eo pipefail 21 22 if [ -n "$XDG_CONFIG_HOME" ]; then 23 echo >&2 "$(tput setaf 3)warning: \$XDG_CONFIG_HOME=$XDG_CONFIG_HOME$(tput sgr 0)" 24 fi 25 ''; 26in 27buildGoPackage rec { 28 pname = "container-toolkit/container-toolkit"; 29 version = "1.9.0"; 30 31 src = fetchFromGitLab { 32 owner = "nvidia"; 33 repo = pname; 34 rev = "v${version}"; 35 sha256 = "sha256-b4mybNB5FqizFTraByHk5SCsNO66JaISj18nLgLN7IA="; 36 }; 37 38 goPackagePath = "github.com/NVIDIA/nvidia-container-toolkit"; 39 40 ldflags = [ "-s" "-w" ]; 41 42 nativeBuildInputs = [ makeWrapper ]; 43 44 preBuild = '' 45 # replace the default hookDefaultFilePath to the $out path 46 substituteInPlace go/src/github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-container-runtime/main.go \ 47 --replace '/usr/bin/nvidia-container-runtime-hook' '${placeholder "out"}/bin/nvidia-container-runtime-hook' 48 ''; 49 50 postInstall = '' 51 mkdir -p $out/etc/nvidia-container-runtime 52 53 # nvidia-container-runtime invokes docker-runc or runc if that isn't 54 # available on PATH. 55 # 56 # Also set XDG_CONFIG_HOME if it isn't already to allow overriding 57 # configuration. This in turn allows users to have the nvidia container 58 # runtime enabled for any number of higher level runtimes like docker and 59 # podman, i.e., there's no need to have mutually exclusivity on what high 60 # level runtime can enable the nvidia runtime because each high level 61 # runtime has its own config.toml file. 62 wrapProgram $out/bin/nvidia-container-runtime \ 63 --run "${warnIfXdgConfigHomeIsSet}" \ 64 --prefix PATH : ${isolatedContainerRuntimePath}:${libnvidia-container}/bin \ 65 --set-default XDG_CONFIG_HOME $out/etc 66 67 cp ${configTemplate} $out/etc/nvidia-container-runtime/config.toml 68 69 substituteInPlace $out/etc/nvidia-container-runtime/config.toml \ 70 --subst-var-by glibcbin ${lib.getBin glibc} 71 72 ln -s $out/bin/nvidia-container-{toolkit,runtime-hook} 73 74 wrapProgram $out/bin/nvidia-container-toolkit \ 75 --add-flags "-config ${placeholder "out"}/etc/nvidia-container-runtime/config.toml" 76 ''; 77 78 meta = with lib; { 79 homepage = "https://gitlab.com/nvidia/container-toolkit/container-toolkit"; 80 description = "NVIDIA Container Toolkit"; 81 license = licenses.asl20; 82 platforms = platforms.linux; 83 maintainers = with maintainers; [ cpcloud ]; 84 }; 85}