From a1318915d36065a6ada12cf2883e086632db65e6 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 5 Aug 2024 16:36:56 +0800 Subject: [PATCH] singularity-tools: deprecate build helpers mkLayer and shellScript Deprecate singularity-tools.mkLayer and singularity-tools.shellScript, for they are no longer related to image building. Use writers.writeBash instead of singularity-tools.shellScript. --- .../manual/release-notes/rl-2411.section.md | 2 + .../singularity-tools/default.nix | 58 ++++++++++++------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index 72768d09607d..da9dd0a18274 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -126,6 +126,8 @@ - `singularity-tools` have the `storeDir` argument removed from its override interface and use `builtins.storeDir` instead. +- Two build helpers in `singularity-tools`, i.e., `mkLayer` and `shellScript`, are deprecated, as they are no longer involved in image-building. Maintainers will remove them in future releases. + - The `budgie` and `budgiePlugins` scope have been removed and their packages moved into the top level scope (i.e., `budgie.budgie-desktop` is now `budgie-desktop`) diff --git a/pkgs/build-support/singularity-tools/default.nix b/pkgs/build-support/singularity-tools/default.nix index 010ed0db9fda..ef8ca167b336 100644 --- a/pkgs/build-support/singularity-tools/default.nix +++ b/pkgs/build-support/singularity-tools/default.nix @@ -5,8 +5,10 @@ runCommand, vmTools, writeClosure, + writers, writeScript, # Native build inputs + buildPackages, e2fsprogs, util-linux, # Build inputs @@ -19,27 +21,37 @@ let defaultSingularity = singularity; in rec { + # TODO(@ShamrockLee): Remove after Nixpkgs 24.11 branch-off. shellScript = - name: text: - writeScript name '' - #!${runtimeShell} - set -e - ${text} - ''; + lib.warn + "`singularity-tools.shellScript` is deprecated. Use `writeScript`, `writeShellScripts` or `writers.writeBash` instead." + ( + name: text: + writeScript name '' + #!${runtimeShell} + set -e + ${text} + '' + ); + # TODO(@ShamrockLee): Remove after Nixpkgs 24.11 branch-off. mkLayer = - { - name, - contents ? [ ], - # May be "apptainer" instead of "singularity" - projectName ? (singularity.projectName or "singularity"), - }: - runCommand "${projectName}-layer-${name}" { inherit contents; } '' - mkdir $out - for f in $contents ; do - cp -ra $f $out/ - done - ''; + lib.warn + "`singularity-tools.mkLayer` is deprecated, as it is no longer used to implement `singularity-tools.buildImages`." + ( + { + name, + contents ? [ ], + # May be "apptainer" instead of "singularity" + projectName ? (singularity.projectName or "singularity"), + }: + runCommand "${projectName}-layer-${name}" { inherit contents; } '' + mkdir $out + for f in $contents ; do + cp -ra $f $out/ + done + '' + ); buildImage = { @@ -53,8 +65,14 @@ rec { }: let projectName = singularity.projectName or "singularity"; - runAsRootFile = shellScript "run-as-root.sh" runAsRoot; - runScriptFile = shellScript "run-script.sh" runScript; + runAsRootFile = buildPackages.writers.writeBash "run-as-root.sh" '' + set -e + ${runAsRoot} + ''; + runScriptFile = writers.writeBash "run-script.sh" '' + set -e + ${runScript} + ''; result = vmTools.runInLinuxVM ( runCommand "${projectName}-image-${name}.sif" {