From af7894cf1d695551ffc2211314d6f9bc5cc05feb Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 21 Nov 2026 02:20:34 +0000 Subject: run-firecracker-vm: fc.home.required, for layers with state in /home A layer that keeps its state in /home can set fc.home.required, and the run script then refuses to start the guest without --home, instead of booting with /home on the tmpfs, where the state is gone when the guest exits. --- pkgs/run-firecracker-vm/default.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'pkgs') diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix index 03d5e09..4c266c0 100644 --- a/pkgs/run-firecracker-vm/default.nix +++ b/pkgs/run-firecracker-vm/default.nix @@ -59,6 +59,15 @@ let (modulesPath + "/profiles/perlless.nix") { fileSystems = imageFileSystems (n + 1); } { systemd.generators.fc-home = homeGenerator (drive (n + 2)); } + { + # For a layer whose state is in /home: the run script then + # refuses to start the guest without --home. + options.fc.home.required = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Whether the guest needs a /home drive (--home)."; + }; + } ] ++ lib.take n layers; # Activate and switch root from the initrd with a single program, @@ -455,7 +464,8 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' # boots (created if it doesn't exist, of --store-size, default 16G; the # file is sparse, so that's only an upper limit). /home is part of the # guest's root file system, gone when it exits, or with --home, on FILE, - # likewise (of --home-size, default 16G). + # likewise (of --home-size, default 16G). A guest with fc.home.required + # (set by a layer) doesn't start without --home. # --mem-size sets the guest's memory, in MiB (default 1024). # The guest's egress goes by the user's whitelist LIST (default: the # VM's name, or without one, default), see modules/host and fc-egress. @@ -501,6 +511,12 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' esac done egress=''${egress:-''${name:-default}} + ${lib.optionalString nixos.config.fc.home.required '' + if test -z "$home"; then + echo "$0: the guest keeps its state in /home: --home FILE is required" >&2 + exit 1 + fi + ''} if ! printf %s "$mem_size" | grep -qxE '[1-9][0-9]*'; then echo "$0: bad memory size: $mem_size (MiB, a number)" >&2 exit 1 -- cgit v1.3.1