diff options
Diffstat (limited to 'pkgs/run-firecracker-vm')
| -rw-r--r-- | pkgs/run-firecracker-vm/default.nix | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix index 8cf8da4..7c0235b 100644 --- a/pkgs/run-firecracker-vm/default.nix +++ b/pkgs/run-firecracker-vm/default.nix @@ -21,7 +21,7 @@ let # stdin and stdout (nofork). Separate -o options, as socat would take # commas as its own option separators. In the initrd, too, for the # store. More options for PORT can come from the kernel command line, - # as fc.9pPORT=OPTIONS (see --nixpkgs-cache in the run script); they come + # as rig.9pPORT=OPTIONS (see --nixpkgs-cache in the run script); they come # last, so they win. mountVsock9p = pkgs.writeShellScript "mount.vsock9p" '' # usage: mount.vsock9p PORT DIR [-o OPTIONS] @@ -38,7 +38,7 @@ let fi read -r cmdline < /proc/cmdline for arg in $cmdline; do - case $arg in fc.9p$1=*) add "''${arg#*=}" + case $arg in rig.9p$1=*) add "''${arg#*=}" esac done exec ${pkgs.socat}/bin/socat VSOCK-CONNECT:2:"$1" EXEC:"${pkgs.util-linux}/bin/mount -t 9p -o trans=fd -o rfdno=0 -o wfdno=1 -o version=9p2000.L -o msize=1048576$opts vsock9p $2",nofork @@ -113,14 +113,14 @@ let (modulesPath + "/profiles/minimal.nix") (modulesPath + "/profiles/perlless.nix") { fileSystems = imageFileSystems (n + 1); } - { systemd.generators.fc-home = homeGenerator (label "fc-home"); } + { systemd.generators.rig-home = homeGenerator (label "rig-home"); } # /xchg: a directory of the host's, via 9P on vsock port 564, only - # with fc.xchg on the kernel command line (run-firecracker-vm + # with rig.xchg on the kernel command line (run-firecracker-vm # --xchg DIR), mounted when first used. A generator, so a guest # without it has no /xchg at all. - { systemd.generators.fc-xchg = pkgs.writeShellScript "fc-xchg-generator" '' + { systemd.generators.rig-xchg = pkgs.writeShellScript "rig-xchg-generator" '' read -r cmdline < /proc/cmdline - case " $cmdline " in *" fc.xchg "*) ;; *) exit 0 + case " $cmdline " in *" rig.xchg "*) ;; *) exit 0 esac printf '%s\n' '[Mount]' 'What=564' 'Where=/xchg' 'Type=vsock9p' > "$1"/xchg.mount printf '%s\n' '[Automount]' 'Where=/xchg' > "$1"/xchg.automount @@ -128,7 +128,7 @@ let ${pkgs.coreutils}/bin/ln -s ../xchg.automount "$1"/local-fs.target.wants/xchg.automount ''; } - # reboot and poweroff both end the VM, whichever the VMM (fc.vmm, + # reboot and poweroff both end the VM, whichever the VMM (rig.vmm, # from the run script): Firecracker ends on a reset (reboot=k), but # stays on poweroff, with the guest halted; Cloud Hypervisor ends on # poweroff, but restarts the guest on a reset. So the shutdown's @@ -137,21 +137,21 @@ let # Hypervisor, after the same clean shutdown. (Not a hook of # systemd-shutdown: it runs those after unmounting, i.e. without # /etc.) - { systemd.generators.fc-vmm-exit = pkgs.writeShellScript "fc-vmm-exit" '' + { systemd.generators.rig-vmm-exit = pkgs.writeShellScript "rig-vmm-exit" '' read -r cmdline < /proc/cmdline exit_by() { # ACTION UNIT... action=$1 shift for unit; do ${pkgs.coreutils}/bin/mkdir -p "$dir/$unit.d" - printf '[Unit]\nSuccessAction=%s\n' "$action" > "$dir/$unit.d/fc-vmm-exit.conf" + printf '[Unit]\nSuccessAction=%s\n' "$action" > "$dir/$unit.d/rig-vmm-exit.conf" done } dir=$1 case " $cmdline " in - *" fc.vmm=firecracker "*) + *" rig.vmm=firecracker "*) exit_by reboot-force systemd-poweroff.service systemd-halt.service ;; - *" fc.vmm=cloud-hypervisor "*) + *" rig.vmm=cloud-hypervisor "*) exit_by poweroff-force systemd-reboot.service systemd-halt.service ;; esac ''; @@ -159,14 +159,14 @@ let { # 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 { + options.rig.home.required = lib.mkOption { type = lib.types.bool; default = false; description = "Whether the guest needs a /home drive (--home)."; }; # For layers/nix.nix, which sets it: the run script gives the # guest the drive for the rw-store, and so on. - options.fc.nix = lib.mkOption { + options.rig.nix = lib.mkOption { type = lib.types.bool; default = false; internal = true; @@ -174,12 +174,12 @@ let }; # The store's lower layers: the images (from the layers), and # what layers add, like layers/nix.nix the host's store. - options.fc.storeLowerdirs = lib.mkOption { + options.rig.storeLowerdirs = lib.mkOption { type = lib.types.listOf lib.types.str; internal = true; description = "The store's lower layers, as in the guest's /."; }; - options.fc.mountVsock9p = lib.mkOption { + options.rig.mountVsock9p = lib.mkOption { type = lib.types.package; default = mountVsock9p; readOnly = true; @@ -188,8 +188,8 @@ let }; # Secrets the guest needs, from the run script (--secret # NAME=FILE, which it requires for each of these), never in the - # store: fc-secrets puts them into place, below /run, at boot. - options.fc.secrets = lib.mkOption { + # store: rig-secrets puts them into place, below /run, at boot. + options.rig.secrets = lib.mkOption { type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: { options = { path = lib.mkOption { @@ -212,13 +212,13 @@ let # about. nix.enable = lib.mkDefault false; assertions = [{ - assertion = config.nix.enable == config.fc.nix; + assertion = config.nix.enable == config.rig.nix; message = "nix.enable: use run-firecracker-vm's layers/nix.nix instead."; }] ++ lib.mapAttrsToList (name: s: { assertion = builtins.match "[A-Za-z0-9._-]+" name != null && builtins.match "/run/[^ ]+" s.path != null; - message = "fc.secrets.${name}: a name of letters, digits, '.', '_' and '-', with a path below /run"; - }) config.fc.secrets; + message = "rig.secrets.${name}: a name of letters, digits, '.', '_' and '-', with a path below /run"; + }) config.rig.secrets; # Activate and switch root from the initrd with a single program, # instead of bash running prepare-root and the activation script. @@ -250,13 +250,13 @@ let # that a single option (lowerdir=A:B:...), which the mount API caps # at 255 bytes, i.e. about 10 images; a lowerdir+= each has no such # limit. An upper layer (layers/nix.nix) adds its own options. - fc.storeLowerdirs = lib.mkBefore lowerdirs; # images first: 9P is slow + rig.storeLowerdirs = lib.mkBefore lowerdirs; # images first: 9P is slow fileSystems."/nix/store" = - if lib.length config.fc.storeLowerdirs > 1 then { + if lib.length config.rig.storeLowerdirs > 1 then { fsType = "overlay"; device = "overlay"; - depends = config.fc.storeLowerdirs; - options = map (d: "lowerdir+=/sysroot${d}") config.fc.storeLowerdirs; + depends = config.rig.storeLowerdirs; + options = map (d: "lowerdir+=/sysroot${d}") config.rig.storeLowerdirs; } else (imageFileSystems 1)."/nix/.image/0"; @@ -268,7 +268,7 @@ let environment.systemPackages = [ fc-egress ]; # sshd, started on demand (a layer may turn that off), with the host - # key a secret (--secret ssh_host_ed25519_key=FILE; see fc-secrets), + # key a secret (--secret ssh_host_ed25519_key=FILE; see rig-secrets), # in place before sshd (or its socket) starts, and never one # generated instead. Who may log in: # users.users.<name>.openssh.authorizedKeys, e.g. in a layer. @@ -278,19 +278,19 @@ let generateHostKeys = false; hostKeys = [{ path = "/run/ssh/ssh_host_ed25519_key"; type = "ed25519"; }]; }; - fc.secrets.ssh_host_ed25519_key = lib.mkIf config.services.openssh.enable { + rig.secrets.ssh_host_ed25519_key = lib.mkIf config.services.openssh.enable { path = "/run/ssh/ssh_host_ed25519_key"; mode = "0600"; }; - # The secrets (fc.secrets), which the run script serves via 9P on + # The secrets (rig.secrets), which the run script serves via 9P on # vsock port 567 (--secret NAME=FILE; never in the store), copied # into place, each with its owner and mode, before sysinit.target # (so before any service with the default dependencies), but after # the users get created, for the owners; any other secret the run # script was given goes to /run/secrets/NAME, root's. The share # gets unmounted again. - systemd.services.fc-secrets = { + systemd.services.rig-secrets = { wantedBy = [ "sysinit.target" ]; before = [ "sysinit.target" "shutdown.target" ]; after = [ "userborn.service" "systemd-sysusers.service" ]; @@ -305,11 +305,11 @@ let install -d -m 0755 /run/secrets ${lib.concatStrings (lib.mapAttrsToList (name: s: '' install -D -o ${lib.escapeShellArg s.owner} -g ${lib.escapeShellArg s.group} -m ${s.mode} "$share"/${name} ${lib.escapeShellArg s.path} - '') config.fc.secrets)} + '') config.rig.secrets)} for f in "$share"/*; do test -f "$f" || continue case ''${f##*/} in - ${lib.concatStringsSep " | " ([ "/" ] ++ lib.attrNames config.fc.secrets)}) ;; # / is no name + ${lib.concatStringsSep " | " ([ "/" ] ++ lib.attrNames config.rig.secrets)}) ;; # / is no name *) install -m 0400 "$f" /run/secrets/ esac done @@ -430,13 +430,13 @@ let }; }; - # /home: part of / (the tmpfs), or with fc.home on the kernel command - # line (--home, see the run script), the drive labelled fc-home (device). + # /home: part of / (the tmpfs), or with rig.home on the kernel command + # line (--home, see the run script), the drive labelled rig-home (device). # A generator rather than fileSystems, so a guest without it doesn't wait # for the drive. - homeGenerator = device: pkgs.writeShellScript "fc-home-generator" '' + homeGenerator = device: pkgs.writeShellScript "rig-home-generator" '' read -r cmdline < /proc/cmdline - case " $cmdline " in *" fc.home "*) ;; *) exit 0 + case " $cmdline " in *" rig.home "*) ;; *) exit 0 esac printf '%s\n' \ '[Unit]' 'Before=local-fs.target' \ @@ -454,10 +454,10 @@ let label = l: "/dev/disk/by-label/${l}"; # The images, read-only drives, image k (of layer k) labelled - # fc-layer-K. + # rig-layer-K. imageFileSystems = count: lib.listToAttrs (lib.genList (k: lib.nameValuePair "/nix/.image/${toString k}" { - device = label "fc-layer-${toString k}"; + device = label "rig-layer-${toString k}"; fsType = "erofs"; options = [ "ro" "nodev" "nosuid" ]; neededForBoot = true; @@ -467,7 +467,7 @@ let nixos = lib.last systems; toplevels = map (s: s.config.system.build.toplevel) systems; inherit (nixos.config.system.build) toplevel kernel initialRamdisk; - nix = nixos.config.fc.nix; # layers/nix.nix + nix = nixos.config.rig.nix; # layers/nix.nix # A layer's name, for its image's: its file's, if it's a file (for # .../NAME/default.nix, NAME). @@ -485,7 +485,7 @@ let # the guest never reads (for nix, the host's store still has them). initrds = map (s: "${s.config.system.build.initialRamdisk}") systems; images = lib.imap0 (k: top: let name = lib.elemAt layerNames k; in pkgs.runCommand - "firecracker-layer-${toString k}${lib.optionalString (name != null) "-${lib.strings.sanitizeDerivationName name}"}.img" { + "rig-layer-${toString k}${lib.optionalString (name != null) "-${lib.strings.sanitizeDerivationName name}"}.img" { nativeBuildInputs = [ pkgs.erofs-utils pkgs.gnutar ]; closure = pkgs.closureInfo { rootPaths = [ top ]; }; below = map (t: pkgs.closureInfo { rootPaths = [ t ]; }) (lib.take k toplevels); @@ -498,7 +498,7 @@ let tar -c -P --verbatim-files-from \ --transform 'flags=rSh;s|^/nix/store/||' \ --files-from - | - mkfs.erofs --quiet -L fc-layer-${toString k} --tar=f --force-uid=0 --force-gid=0 --hard-dereference -T 0 $out + mkfs.erofs --quiet -L rig-layer-${toString k} --tar=f --force-uid=0 --force-gid=0 --hard-dereference -T 0 $out '') toplevels; config = pkgs.writeText "firecracker.json" (builtins.toJSON { @@ -508,7 +508,7 @@ let boot_args = toString (nixos.config.boot.kernelParams ++ [ "init=${toplevel}/init" ] ++ lib.optional nix - "fc.registration=${pkgs.closureInfo { rootPaths = [ toplevel ]; }}/registration" + "rig.registration=${pkgs.closureInfo { rootPaths = [ toplevel ]; }}/registration" ++ [ "@ARGS@" ]); @@ -580,7 +580,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' # 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). A guest with fc.home.required (set by a + # --home-size, default 16G). A guest with rig.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 @@ -590,11 +590,11 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' # guest's number of CPUs (default 2; Firecracker takes 1 to 32). # --secret NAME=FILE: a secret for the guest, NAME letters, digits, '.', # '_' and '-', FILE read once (it may be a pipe, like <(...)), and handed - # to the guest only, never in the store (see fc-secrets); a guest - # doesn't start without the secrets it declares (fc.secrets). + # to the guest only, never in the store (see rig-secrets); a guest + # doesn't start without the secrets it declares (rig.secrets). # --vmm: the hypervisor, Firecracker (default) or Cloud Hypervisor, which # takes no commas in --store and --home. Either ends when the guest - # reboots or powers off (see fc-vmm-exit). + # reboots or powers off (see rig-vmm-exit). # --nested: hardware virtualization (SVM, VMX) for the guest, so it can # run VMs itself (base/kernel.nix has KVM); off by default, as it's more # of the host's KVM for the guest to reach. @@ -630,7 +630,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' --home-size) home_size=$2; shift 2 ;; --mem-size) mem_size=$2; shift 2 ;; --nixpkgs) nixpkgs=$2; nix_opt=$1; shift 2 ;; - --nixpkgs-cache) args="$args fc.9p566=cache=$2"; nixpkgs_cache=$2; nix_opt=$1; shift 2 ;; + --nixpkgs-cache) args="$args rig.9p566=cache=$2"; nixpkgs_cache=$2; nix_opt=$1; shift 2 ;; --egress) egress=$2; shift 2 ;; --name) name=$2; shift 2 ;; --vcpus) vcpus=$2; shift 2 ;; @@ -643,7 +643,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' esac done egress=''${egress:-''${name:-default}} - ${lib.optionalString nixos.config.fc.home.required '' + ${lib.optionalString nixos.config.rig.home.required '' if test -z "$home"; then echo "$0: the guest keeps its state in /home: --home FILE is required" >&2 exit 1 @@ -680,17 +680,17 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' echo "$0: bad --vmm: $vmm (firecracker or cloud-hypervisor)" >&2 exit 1 esac - args="$args fc.vmm=$vmm" # see fc-vmm-exit + args="$args rig.vmm=$vmm" # see rig-vmm-exit if test -n "$xchg"; then - args="$args fc.xchg" # see fc-xchg + args="$args rig.xchg" # see rig-xchg fi tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT # The secrets, copies, in a directory only the user can read, for the - # guest to copy (see fc-secrets), each FILE read once. The guest's own - # (fc.secrets) are required. + # guest to copy (see rig-secrets), each FILE read once. The guest's own + # (rig.secrets) are required. mkdir -m 700 "$tmp"/secrets for secret in ''${secrets[@]+"''${secrets[@]}"}; do s=''${secret%%=*} @@ -721,7 +721,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' exit 1 fi fi - for s in ${lib.escapeShellArgs (lib.attrNames nixos.config.fc.secrets)}; do + for s in ${lib.escapeShellArgs (lib.attrNames nixos.config.rig.secrets)}; do if ! test -e "$tmp/secrets/$s"; then echo "$0: the guest needs the secret $s: --secret $s=FILE is required" >&2 exit 1 @@ -729,8 +729,8 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' done for s in $(ls "$tmp"/secrets); do case $s in - ${lib.concatStringsSep " | " ([ "/" ] ++ lib.attrNames nixos.config.fc.secrets)}) ;; # / is no name - *) echo "$0: --secret $s: the guest doesn't ask for it (fc.secrets), it goes to /run/secrets/$s" >&2 + ${lib.concatStringsSep " | " ([ "/" ] ++ lib.attrNames nixos.config.rig.secrets)}) ;; # / is no name + *) echo "$0: --secret $s: the guest doesn't ask for it (rig.secrets), it goes to /run/secrets/$s" >&2 esac done @@ -757,11 +757,11 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' printf -v "$1" %s "$f" } if test -n "$rw_store"; then - disk rw_store "$rw_store" "$rw_store_size" fc-store + disk rw_store "$rw_store" "$rw_store_size" rig-store fi if test -n "$home"; then - disk home "$home" "$home_size" fc-home - args="$args fc.home" + disk home "$home" "$home_size" rig-home + args="$args rig.home" fi # Tell systemd the terminal's type and size, so it doesn't query them via @@ -906,11 +906,11 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' serve 565 /nix/store serve 566 "$nixpkgs" # With a cache mode for nixpkgs, the guest doesn't see changes to it - # (see fc-drop-caches in layers/nix.nix). When it's a Git checkout + # (see rig-drop-caches in layers/nix.nix). When it's a Git checkout # whose commit changes (checkout, pull, rebase), the guest gets told # to drop its caches: a connection to its vsock port 1235 (on the # socket uds_path, with CONNECT PORT). Changes without a commit - # need fc-drop-caches by hand. + # need rig-drop-caches by hand. if test -n "$nixpkgs_cache" && git -C "$nixpkgs" rev-parse HEAD > /dev/null 2>&1; then ( close_locks |
