summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2016-11-14 12:26:59 +1100
committerJustin Bedo <cu@cua0.org>2016-11-15 09:11:53 +1100
commit04121437bea46a74c71eaca507007a4e9c9ac20a (patch)
tree57e8318c60d0cfe7a424efc2503e956543f114ee /pkgs
parent7f71b89454ebfb0699ca441329f8cb36466d74ee (diff)
downloadnixpkgs-04121437bea46a74c71eaca507007a4e9c9ac20a.tar
nixpkgs-04121437bea46a74c71eaca507007a4e9c9ac20a.tar.gz
nixpkgs-04121437bea46a74c71eaca507007a4e9c9ac20a.tar.bz2
nixpkgs-04121437bea46a74c71eaca507007a4e9c9ac20a.tar.lz
nixpkgs-04121437bea46a74c71eaca507007a4e9c9ac20a.tar.xz
nixpkgs-04121437bea46a74c71eaca507007a4e9c9ac20a.tar.zst
nixpkgs-04121437bea46a74c71eaca507007a4e9c9ac20a.zip
singularity: init 2.2
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/applications/virtualization/singularity/default.nix25
-rw-r--r--pkgs/build-support/singularity-tools/default.nix100
-rw-r--r--pkgs/top-level/all-packages.nix4
3 files changed, 129 insertions, 0 deletions
diff --git a/pkgs/applications/virtualization/singularity/default.nix b/pkgs/applications/virtualization/singularity/default.nix
new file mode 100644
index 00000000000..e318a0b64d7
--- /dev/null
+++ b/pkgs/applications/virtualization/singularity/default.nix
@@ -0,0 +1,25 @@
+{ stdenv
+, fetchFromGitHub
+, autoreconfHook }:
+
+stdenv.mkDerivation rec {
+  name = "singularity-${version}";
+  version = "2.2";
+
+  src = fetchFromGitHub {
+    owner = "singularityware";
+    repo = "singularity";
+    rev = version;
+    sha256 = "19g43gfdy5s8y4252474cp39d6ypn5dd37wp0s21fgd13vqy26px";
+  };
+
+  buildInputs = [ autoreconfHook ];
+
+  meta = with stdenv.lib; {
+    homepage = http://singularity.lbl.gov/;
+    description = "Designed around the notion of extreme mobility of compute and reproducible science, Singularity enables users to have full control of their operating system environment";
+    license = "BSD license with 2 modifications";
+    platforms = platforms.linux;
+    maintainers = [ maintainers.jbedo ];
+  };
+}
diff --git a/pkgs/build-support/singularity-tools/default.nix b/pkgs/build-support/singularity-tools/default.nix
new file mode 100644
index 00000000000..3c27b9fc1ad
--- /dev/null
+++ b/pkgs/build-support/singularity-tools/default.nix
@@ -0,0 +1,100 @@
+{ runCommand
+, stdenv
+, storeDir ? builtins.storeDir
+, writeScript
+, singularity
+, writeReferencesToFile
+, bash
+, vmTools
+, gawk
+, utillinux
+, e2fsprogs
+, squashfsTools }:
+
+rec {
+  shellScript = name: text:
+    writeScript name ''
+      #!${stdenv.shell}
+      set -e
+      ${text}
+    '';
+
+  mkLayer = {
+    name,
+    contents ? [],
+  }:
+    runCommand "singularity-layer-${name}" {
+      inherit contents;
+    } ''
+      mkdir $out
+      for f in $contents ; do
+        cp -ra $f $out/
+      done
+    '';
+
+  buildImage = {
+    name,
+    contents ? [],
+    diskSize ? 1024,
+    runScript ? "#!${stdenv.shell}\nexec /bin/sh",
+    runAsRoot ? null,
+    extraSpace ? 0
+  }:
+    let layer = mkLayer {
+          inherit name;
+          contents = contents ++ [ bash runScriptFile ];
+          };
+        runAsRootFile = shellScript "run-as-root.sh" runAsRoot;
+        runScriptFile = shellScript "run-script.sh" runScript;
+        result = vmTools.runInLinuxVM (
+          runCommand "singularity-image-${name}.img" {
+            buildInputs = [ singularity e2fsprogs utillinux gawk ];
+            layerClosure = writeReferencesToFile layer;
+            preVM = vmTools.createEmptyImage {
+              size = diskSize;
+              fullName = "singularity-run-disk";
+            };
+          }
+          ''
+            rm -rf $out
+            mkdir disk
+            mkfs -t ext3 -b 4096 /dev/${vmTools.hd}
+            mount /dev/${vmTools.hd} disk
+            cd disk
+
+            # Run root script
+            ${stdenv.lib.optionalString (runAsRoot != null) ''
+              mkdir -p ./${storeDir}
+              mount --rbind ${storeDir} ./${storeDir}
+              unshare -imnpuf --mount-proc chroot ./ ${runAsRootFile}
+              umount -R ./${storeDir}
+            ''}
+
+            # Build /bin and copy across closure
+            mkdir -p bin nix/store
+            for f in $(cat $layerClosure) ; do
+              cp -ar $f ./$f
+              for f in $f/bin/* ; do
+                if [ ! -e bin/$(basename $f) ] ; then
+                  ln -s $f bin/
+                fi
+              done
+            done
+
+            # Create runScript
+            ln -s ${runScriptFile} singularity
+
+            # Size calculation
+            cd ..
+            umount disk
+            size=$(resize2fs -P /dev/${vmTools.hd} | awk '{print $NF}')
+            mount /dev/${vmTools.hd} disk
+            cd disk
+
+            export PATH=$PATH:${e2fsprogs}/bin/
+            singularity create -s $((1 + size * 4 / 1024 + ${toString extraSpace})) $out
+            tar -c . | singularity import $out
+          '');
+
+    in result;
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index b3a881fc9ad..63c725e2625 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -282,6 +282,8 @@ in
 
   pathsFromGraph = ../build-support/kernel/paths-from-graph.pl;
 
+  singularity-tools = callPackage ../build-support/singularity-tools { };
+
   srcOnly = args: callPackage ../build-support/src-only args;
 
   substituteAll = callPackage ../build-support/substitute/substitute-all.nix { };
@@ -13253,6 +13255,8 @@ in
 
   slack = callPackage ../applications/networking/instant-messengers/slack { };
 
+  singularity = callPackage ../applications/virtualization/singularity { };
+
   spectrwm = callPackage ../applications/window-managers/spectrwm { };
 
   wlc = callPackage ../development/libraries/wlc { };