Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

singularity-tools: format expression #332168

Merged
merged 2 commits into from
Aug 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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