diff options
| author | tv <tv@krebsco.de> | 2026-11-21 02:20:34 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-21 04:03:41 +0100 |
| commit | af7894cf1d695551ffc2211314d6f9bc5cc05feb (patch) | |
| tree | 2cc3585637472462ee333e585da62e7dc5505c2e /pkgs/run-firecracker-vm/default.nix | |
| parent | ddf2ffd52fc27e4abae1f2f06abd90411b1e0f47 (diff) | |
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.
Diffstat (limited to 'pkgs/run-firecracker-vm/default.nix')
| -rw-r--r-- | pkgs/run-firecracker-vm/default.nix | 18 |
1 files changed, 17 insertions, 1 deletions
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 |
