diff options
| -rw-r--r-- | README.md | 9 | ||||
| -rw-r--r-- | pkgs/run-firecracker-vm/default.nix | 18 |
2 files changed, 26 insertions, 1 deletions
@@ -77,6 +77,15 @@ from the store, so either can be kept or thrown away): ./result/bin/run-firecracker-vm --home ~/fc-home.img [--home-size 50G] ``` +A layer that keeps its state in `/home` can make that disk mandatory, +so the state doesn't silently end up on the tmpfs: + +```nix +{ fc.home.required = true; } +``` + +The run script then refuses to start the guest without `--home`. + `/nixpkgs` is the nixpkgs the guest was built from (`<nixpkgs>`, checkout or not); `--nixpkgs DIR` serves another one. It's not cached in the guest, so changes to it show up right away, but evaluating is slow; 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 |
