diff options
Diffstat (limited to 'nixpkgs/pkgs/applications/virtualization/singularity/generic.nix')
-rw-r--r-- | nixpkgs/pkgs/applications/virtualization/singularity/generic.nix | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/nixpkgs/pkgs/applications/virtualization/singularity/generic.nix b/nixpkgs/pkgs/applications/virtualization/singularity/generic.nix index 9f17dc8eb03d..85992e2abce9 100644 --- a/nixpkgs/pkgs/applications/virtualization/singularity/generic.nix +++ b/nixpkgs/pkgs/applications/virtualization/singularity/generic.nix @@ -27,12 +27,14 @@ in , buildGoModule , runCommandLocal # Native build inputs +, addDriverRunpath , makeWrapper , pkg-config , util-linux , which # Build inputs , bash +, callPackage , conmon , coreutils , cryptsetup @@ -54,6 +56,9 @@ in , hello # Overridable configurations , enableNvidiaContainerCli ? true + # --nvccli currently requires extra privileges: + # https://github.com/apptainer/apptainer/issues/1893#issuecomment-1881240800 +, forceNvcCli ? false # Compile with seccomp support # SingularityCE 3.10.0 and above requires explicit --without-seccomp when libseccomp is not available. , enableSeccomp ? true @@ -65,6 +70,7 @@ in # Whether to compile with SUID support , enableSuid ? false , starterSuidPath ? null +, substituteAll # newuidmapPath and newgidmapPath are to support --fakeroot # where those SUID-ed executables are unavailable from the FHS system PATH. # Path to SUID-ed newuidmap executable @@ -94,6 +100,10 @@ in (buildGoModule { inherit pname version src; + patches = lib.optionals (projectName == "apptainer") [ + (substituteAll { src = ./apptainer/0001-ldCache-patch-for-driverLink.patch; inherit (addDriverRunpath) driverLink; }) + ]; + # Override vendorHash with the output got from # nix-prefetch -E "{ sha256 }: ((import ./. { }).apptainer.override { vendorHash = sha256; }).goModules" # or with `null` when using vendored source tarball. @@ -175,11 +185,18 @@ in if [[ ! -e .git || ! -e VERSION ]]; then echo "${version}" > VERSION fi + # Patch shebangs for script run during build patchShebangs --build "$configureScript" makeit e2e scripts mlocal/scripts + # Patching the hard-coded defaultPath by prefixing the packages in defaultPathInputs substituteInPlace cmd/internal/cli/actions.go \ --replace "defaultPath = \"${defaultPathOriginal}\"" "defaultPath = \"''${defaultPathInputs// /\/bin:}''${defaultPathInputs:+/bin:}${defaultPathOriginal}\"" + + substituteInPlace internal/pkg/util/gpu/nvidia.go \ + --replace \ + 'return fmt.Errorf("/usr/bin not writable in the container")' \ + "" ''; postConfigure = '' @@ -212,7 +229,7 @@ in wrapProgram "$out/bin/${projectName}" \ --prefix PATH : "''${defaultPathInputs// /\/bin:}''${defaultPathInputs:+/bin:}" # Make changes in the config file - ${lib.optionalString enableNvidiaContainerCli '' + ${lib.optionalString forceNvcCli '' substituteInPlace "$out/etc/${projectName}/${projectName}.conf" \ --replace "use nvidia-container-cli = no" "use nvidia-container-cli = yes" ''} @@ -264,5 +281,38 @@ in singularity = finalAttrs.finalPackage; }; }; + gpuChecks = lib.optionalAttrs (projectName == "apptainer") { + # Should be in tests, but Ofborg would skip image-hello-cowsay because + # saxpy is unfree. + image-saxpy = callPackage + ({ singularity-tools, cudaPackages }: + singularity-tools.buildImage { + name = "saxpy"; + contents = [ cudaPackages.saxpy ]; + memSize = 2048; + diskSize = 2048; + singularity = finalAttrs.finalPackage; + }) + { }; + saxpy = + callPackage + ({ runCommand, writeShellScriptBin }: + let + unwrapped = writeShellScriptBin "apptainer-cuda-saxpy" + '' + ${lib.getExe finalAttrs.finalPackage} exec --nv $@ ${finalAttrs.passthru.tests.image-saxpy} saxpy + ''; + in + runCommand "run-apptainer-cuda-saxpy" + { + requiredSystemFeatures = [ "cuda" ]; + nativeBuildInputs = [ unwrapped ]; + passthru = { inherit unwrapped; }; + } + '' + apptainer-cuda-saxpy + '') + { }; + }; }; }) |