singularity-tools: make runscript modifiable

This commit is contained in:
Yueh-Shun Li 2024-08-15 18:39:15 +08:00
parent e88a41614f
commit 51ef09110b

View File

@ -5,8 +5,9 @@
runCommand, runCommand,
vmTools, vmTools,
writeClosure, writeClosure,
writers, writeDirectReferencesToFile,
writeScript, writeScript,
writeStringReferencesToFile,
# Native build inputs # Native build inputs
buildPackages, buildPackages,
e2fsprogs, e2fsprogs,
@ -69,10 +70,16 @@ lib.makeExtensible (final: {
set -e set -e
${runAsRoot} ${runAsRoot}
''; '';
runScriptFile = writers.writeBash "run-script.sh" '' runScriptFile = writeScript "run-script.sh" ''
#!/bin/sh
set -e set -e
${runScript} ${runScript}
''; '';
runScriptReferences =
if builtins ? getContext then
lib.splitString "\n" (writeStringReferencesToFile runScriptFile.text).text
else
[ (writeDirectReferencesToFile runScriptFile) ];
result = vmTools.runInLinuxVM ( result = vmTools.runInLinuxVM (
runCommand "${projectName}-image-${name}.sif" runCommand "${projectName}-image-${name}.sif"
{ {
@ -82,13 +89,7 @@ lib.makeExtensible (final: {
util-linux util-linux
]; ];
strictDeps = true; strictDeps = true;
layerClosure = writeClosure ( layerClosure = writeClosure ([ bashInteractive ] ++ runScriptReferences ++ contents);
[
bashInteractive
runScriptFile
]
++ contents
);
preVM = vmTools.createEmptyImage { preVM = vmTools.createEmptyImage {
size = diskSize; size = diskSize;
fullName = "${projectName}-run-disk"; fullName = "${projectName}-run-disk";
@ -134,12 +135,14 @@ lib.makeExtensible (final: {
done done
done done
# Create runScript and link shell # Link /bin/sh
if [ ! -e bin/sh ]; then if [ ! -e bin/sh ]; then
ln -s ${lib.getExe bashInteractive} bin/sh ln -s ${lib.getExe bashInteractive} bin/sh
fi fi
mkdir -p .singularity.d mkdir -p .singularity.d
ln -s ${runScriptFile} .singularity.d/runscript
# Create runscript
cp "${runScriptFile}" .singularity.d/runscript
# Fill out .singularity.d # Fill out .singularity.d
mkdir -p .singularity.d/env mkdir -p .singularity.d/env