aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/run-firecracker-vm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-20 05:09:07 +0000
committertv <tv@krebsco.de>2026-11-20 05:09:07 +0000
commit1d1e32b91fca92e32ab95474dcfdddf43bf03193 (patch)
treeeaecac03c66ddedd8da444e96d78341b2518830a /pkgs/run-firecracker-vm
parent0c5a5f628d8ffe00464fb0671125d185115e8c47 (diff)
run-firecracker-vm: name layer images after their files
A layer's image is now firecracker-layer-K-NAME.img, NAME being the layer's file name without .nix (or, for .../NAME/default.nix, NAME). Layers that aren't files, and the base system, keep just the number.
Diffstat (limited to 'pkgs/run-firecracker-vm')
-rw-r--r--pkgs/run-firecracker-vm/default.nix13
1 files changed, 12 insertions, 1 deletions
diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix
index b7eae84..a0aae13 100644
--- a/pkgs/run-firecracker-vm/default.nix
+++ b/pkgs/run-firecracker-vm/default.nix
@@ -323,9 +323,20 @@ let
toplevels = map (s: s.config.system.build.toplevel) systems;
inherit (nixos.config.system.build) toplevel kernel initialRamdisk;
+ # A layer's name, for its image's: its file's, if it's a file (for
+ # .../NAME/default.nix, NAME).
+ layerName = m:
+ if builtins.isPath m || builtins.isString m && lib.hasPrefix "/" m then
+ let file = baseNameOf (toString m); in
+ if file == "default.nix" then baseNameOf (dirOf (toString m))
+ else lib.removeSuffix ".nix" file
+ else null;
+ layerNames = [ null ] ++ map layerName layers; # the base system: none
+
# Layer k's image: the store paths of its system's closure that aren't
# in the closures of the layers below, as erofs image.
- images = lib.imap0 (k: top: pkgs.runCommand "firecracker-layer-${toString k}.img" {
+ images = lib.imap0 (k: top: let name = lib.elemAt layerNames k; in pkgs.runCommand
+ "firecracker-layer-${toString k}${lib.optionalString (name != null) "-${lib.strings.sanitizeDerivationName name}"}.img" {
nativeBuildInputs = [ pkgs.erofs-utils pkgs.gnutar ];
closure = pkgs.closureInfo { rootPaths = [ top ]; };
below = map (t: pkgs.closureInfo { rootPaths = [ t ]; }) (lib.take k toplevels);