diff options
| author | tv <tv@krebsco.de> | 2026-11-20 05:09:07 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-20 05:09:07 +0000 |
| commit | 1d1e32b91fca92e32ab95474dcfdddf43bf03193 (patch) | |
| tree | eaecac03c66ddedd8da444e96d78341b2518830a | |
| parent | 0c5a5f628d8ffe00464fb0671125d185115e8c47 (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.
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | pkgs/run-firecracker-vm/default.nix | 13 |
2 files changed, 14 insertions, 2 deletions
@@ -90,7 +90,8 @@ nix-build pkgs/run-firecracker-vm --arg layers '[ ./base-tools.nix ./my-service. The guest runs the top layer's system. Each layer gets its own image, with only the store paths the layers below don't have, so the base image, and those of layers below, stay the same whatever goes on top: -a service layer costs a small image of its own. Changing a layer +a service layer costs a small image of its own, named after its file +(`firecracker-layer-2-my-service.img`). Changing a layer changes the images of the layers above it. To use a cut-down kernel, based on Firecracker's recommended guest 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); |
