Skip to content

Commit

Permalink
Merge pull request #332168 from ShamrockLee/singularity-tools-format
Browse files Browse the repository at this point in the history
singularity-tools: format expression
  • Loading branch information
SomeoneSerge authored Aug 4, 2024
2 parents cb9a96f + d17eef5 commit 976c81a
Showing 1 changed file with 40 additions and 30 deletions.
70 changes: 40 additions & 30 deletions pkgs/build-support/singularity-tools/default.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
{ runCommand
, lib
, stdenv
, storeDir ? builtins.storeDir
, writeScript
, singularity
, writeClosure
, bash
, vmTools
, gawk
, util-linux
, runtimeShell
, e2fsprogs
{
lib,
# Build helpers
stdenv,
runCommand,
vmTools,
writeClosure,
writeScript,
# Native build inputs
e2fsprogs,
gawk,
util-linux,
# Build inputs
bash,
runtimeShell,
singularity,
storeDir ? builtins.storeDir,
}:
rec {
shellScript = name: text:
shellScript =
name: text:
writeScript name ''
#!${runtimeShell}
set -e
${text}
'';

mkLayer =
{ name
, contents ? [ ]
{
name,
contents ? [ ],
# May be "apptainer" instead of "singularity"
, projectName ? (singularity.projectName or "singularity")
projectName ? (singularity.projectName or "singularity"),
}:
runCommand "${projectName}-layer-${name}"
{
inherit contents;
} ''
runCommand "${projectName}-layer-${name}" { inherit contents; } ''
mkdir $out
for f in $contents ; do
cp -ra $f $out/
Expand All @@ -40,13 +43,14 @@ rec {
let
defaultSingularity = singularity;
in
{ name
, contents ? [ ]
, diskSize ? 1024
, runScript ? "#!${stdenv.shell}\nexec /bin/sh"
, runAsRoot ? null
, memSize ? 1024
, singularity ? defaultSingularity
{
name,
contents ? [ ],
diskSize ? 1024,
memSize ? 1024,
runAsRoot ? null,
runScript ? "#!${stdenv.shell}\nexec /bin/sh",
singularity ? defaultSingularity,
}:
let
projectName = singularity.projectName or "singularity";
Expand All @@ -55,7 +59,12 @@ rec {
result = vmTools.runInLinuxVM (
runCommand "${projectName}-image-${name}.img"
{
buildInputs = [ singularity e2fsprogs util-linux gawk ];
buildInputs = [
singularity
e2fsprogs
util-linux
gawk
];
layerClosure = writeClosure contents;
preVM = vmTools.createEmptyImage {
size = diskSize;
Expand Down Expand Up @@ -110,7 +119,8 @@ rec {
echo "root:x:0:0:System administrator:/root:/bin/sh" > /etc/passwd
echo > /etc/resolv.conf
TMPDIR=$(pwd -P) ${projectName} build $out ./img
'');
''
);

in
result;
Expand Down

0 comments on commit 976c81a

Please sign in to comment.