singularity-tool: format expression

This commit is contained in:
Yueh-Shun Li
2023-01-29 01:02:47 +08:00
parent 2f04861c8a
commit b33d6407cc
@@ -10,8 +10,8 @@
, gawk
, util-linux
, runtimeShell
, e2fsprogs }:
, e2fsprogs
}:
rec {
shellScript = name: text:
writeScript name ''
@@ -20,35 +20,39 @@ rec {
${text}
'';
mkLayer = {
name,
contents ? [],
}:
runCommand "singularity-layer-${name}" {
inherit contents;
} ''
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,
memSize ? 512
}:
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" {
buildImage =
{ name
, contents ? [ ]
, diskSize ? 1024
, runScript ? "#!${stdenv.shell}\nexec /bin/sh"
, runAsRoot ? null
, memSize ? 512
}:
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 util-linux gawk ];
layerClosure = writeReferencesToFile layer;
preVM = vmTools.createEmptyImage {
@@ -106,5 +110,6 @@ rec {
TMPDIR=$(pwd -P) singularity build $out ./img
'');
in result;
in
result;
}