aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/run-firecracker-vm
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/run-firecracker-vm')
-rw-r--r--pkgs/run-firecracker-vm/default.nix18
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