about summary refs log tree commit diff
path: root/pkgs/build-support/singularity-tools
diff options
context:
space:
mode:
authorYueh-Shun Li <44064051+ShamrockLee@users.noreply.github.com>2023-01-29 01:02:47 +0800
committerYueh-Shun Li <44064051+ShamrockLee@users.noreply.github.com>2023-02-08 18:03:11 +0800
commit50788d2fb00e79c3f3ef720edbb5218d561c8ce7 (patch)
tree5d474620987654651205a1ad295cbb557f863faf /pkgs/build-support/singularity-tools
parentef09cfec0bbba5a4adc4745981053654c6c170f2 (diff)
apptainer, singularity: fix defaultPath and reflect upstream changes
Upstream changes:
singularity 3.8.7 (the legacy) -> apptainer 1.1.3 (the renamed) / singularity 3.10.4 (Sylabs's fork)

Build process:
*   Share between different sources
*   Fix the sed regexp to make defaultPath patch work
*   allowGoReference is now true
*   Provied input parameter removeCompat (default to false)
    that removes the compatible "*singularity*" symbolic links
    and related autocompletion files when projectName != "singularity"
*   Change localstatedir to /var/lib
*   Format with nixpkgs-fmt
*   Fix the defaultPath patching
    and use it instead of the `<executable> path` config directive
    deprecated in Apptainer
*   Provide dependencies for new functionalities such as
    squashfuse (unprivileged squashfs mount)
*   Provide an attribute `defaultPathInputs` to override
    prefix of container runtime default PATH

NixOS module programs.singularity:
*   Allow users to specify packages
*   Place related directories to /var/lib
*   Format with nixpkgs-fmt

singularity-tools:
*   Allow users to specify packages
*   Place related directories to /var/lib when building images in VM
Diffstat (limited to 'pkgs/build-support/singularity-tools')
-rw-r--r--pkgs/build-support/singularity-tools/default.nix29
1 files changed, 18 insertions, 11 deletions
diff --git a/pkgs/build-support/singularity-tools/default.nix b/pkgs/build-support/singularity-tools/default.nix
index bf542e3070086..9689e41245909 100644
--- a/pkgs/build-support/singularity-tools/default.nix
+++ b/pkgs/build-support/singularity-tools/default.nix
@@ -23,9 +23,10 @@ rec {
   mkLayer =
     { name
     , contents ? [ ]
-    ,
+      # May be "apptainer" instead of "singularity"
+    , projectName ? (singularity.projectName or "singularity")
     }:
-    runCommand "singularity-layer-${name}"
+    runCommand "${projectName}-layer-${name}"
       {
         inherit contents;
       } ''
@@ -36,28 +37,34 @@ rec {
     '';
 
   buildImage =
+    let
+      defaultSingularity = singularity;
+    in
     { name
     , contents ? [ ]
     , diskSize ? 1024
     , runScript ? "#!${stdenv.shell}\nexec /bin/sh"
     , runAsRoot ? null
     , memSize ? 512
+    , singularity ? defaultSingularity
     }:
     let
+      projectName = singularity.projectName or "singularity";
       layer = mkLayer {
         inherit name;
         contents = contents ++ [ bash runScriptFile ];
+        inherit projectName;
       };
       runAsRootFile = shellScript "run-as-root.sh" runAsRoot;
       runScriptFile = shellScript "run-script.sh" runScript;
       result = vmTools.runInLinuxVM (
-        runCommand "singularity-image-${name}.img"
+        runCommand "${projectName}-image-${name}.img"
           {
             buildInputs = [ singularity e2fsprogs util-linux gawk ];
             layerClosure = writeReferencesToFile layer;
             preVM = vmTools.createEmptyImage {
               size = diskSize;
-              fullName = "singularity-run-disk";
+              fullName = "${projectName}-run-disk";
             };
             inherit memSize;
           }
@@ -96,18 +103,18 @@ rec {
             if [ ! -e bin/sh ]; then
               ln -s ${runtimeShell} bin/sh
             fi
-            mkdir -p .singularity.d
-            ln -s ${runScriptFile} .singularity.d/runscript
+            mkdir -p .${projectName}.d
+            ln -s ${runScriptFile} .${projectName}.d/runscript
 
-            # Fill out .singularity.d
-            mkdir -p .singularity.d/env
-            touch .singularity.d/env/94-appsbase.sh
+            # Fill out .${projectName}.d
+            mkdir -p .${projectName}.d/env
+            touch .${projectName}.d/env/94-appsbase.sh
 
             cd ..
-            mkdir -p /var/singularity/mnt/{container,final,overlay,session,source}
+            mkdir -p /var/lib/${projectName}/mnt/{container,final,overlay,session,source}
             echo "root:x:0:0:System administrator:/root:/bin/sh" > /etc/passwd
             echo > /etc/resolv.conf
-            TMPDIR=$(pwd -P) singularity build $out ./img
+            TMPDIR=$(pwd -P) ${projectName} build $out ./img
           '');
 
     in