From 1d8327ebfa7bc859ecafb0629c93e756b0b10357 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 20 Nov 2026 02:49:39 +0000 Subject: run-firecracker-vm: store layers The new argument layers is a list of NixOS modules, each a layer on top of the ones before, the first on top of the base system. The guest runs the top layer's system. Each layer gets its own erofs image with only the store paths of its system's closure that the layers below don't have, so the base image (and those of layers below) stays the same whatever goes on top: nix-build pkgs/run-firecracker-vm --arg layers '[ ./my-service.nix ]' The images become read-only drives, mounted as overlay lower layers (with the host store below them, as before). The writable store disk is now the first drive (/dev/vda), the images follow (vdb, vdc, ...). --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index c37b1fb..2b6446a 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,9 @@ console. Boots in about a second and a quarter. Stable Nix, no flakes. The guest gets: -- the host's Nix store, read-only, with its own closure from a local image - for speed, and a writable layer on top, so nix and `nix-shell` work; +- the host's Nix store, read-only, with its own closure from local images + for speed (one per layer, see below), and a writable layer on top, so + nix and `nix-shell` work; - `/xchg`: the directory `xchg` in the current working directory, shared with the host (and with other VMs started in the same directory); - `/nixpkgs`: the host's nixpkgs, read-only, on the guest's `NIX_PATH`; @@ -73,6 +74,19 @@ guest, so changes to it show up right away, but evaluating is slow; not show up while the guest runs). Other modes: `mmap`, `readahead`, `none` (the default). +The guest's system can be built in layers, each a NixOS module on top of +the ones before (the first on top of the base system): + +```sh +nix-build pkgs/run-firecracker-vm --arg layers '[ ./base-tools.nix ./my-service.nix ]' +``` + +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 +changes the images of the layers above it. + To use a cut-down kernel, based on Firecracker's recommended guest configuration, instead of `linuxPackages_latest`: -- cgit v1.3.1