aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--pkgs/run-firecracker-vm/default.nix13
2 files changed, 14 insertions, 2 deletions
diff --git a/README.md b/README.md
index 66eed4a..e2c809f 100644
--- a/README.md
+++ b/README.md
@@ -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);