diff options
Diffstat (limited to 'pkgs/run-firecracker-vm')
| -rw-r--r-- | pkgs/run-firecracker-vm/default.nix | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/pkgs/run-firecracker-vm/default.nix b/pkgs/run-firecracker-vm/default.nix index e225451..8a58c60 100644 --- a/pkgs/run-firecracker-vm/default.nix +++ b/pkgs/run-firecracker-vm/default.nix @@ -536,6 +536,15 @@ let vcpu_count = 2; # --vcpus mem_size_mib = 1024; # --mem-size }; + # No hardware virtualization for the guest (SVM, VMX), unless + # --nested (which drops this): Firecracker passes on what KVM offers. + # The bitmaps go from bit 31 to 0, x keeps a bit. + cpu-config.cpuid_modifiers = [ + { leaf = "0x80000001"; subleaf = "0x0"; flags = 0; # AMD: ECX[2] SVM + modifiers = [ { register = "ecx"; bitmap = "0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0xx"; } ]; } + { leaf = "0x1"; subleaf = "0x0"; flags = 0; # Intel: ECX[5] VMX + modifiers = [ { register = "ecx"; bitmap = "0bxxxxxxxxxxxxxxxxxxxxxxxxxx0xxxxx"; } ]; } + ]; }); in pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' @@ -545,7 +554,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' # [--nixpkgs DIR] [--nixpkgs-cache MODE] # [--egress LIST] [--name NAME] [--vcpus N] # [--secret NAME=FILE]... - # [--vmm firecracker|cloud-hypervisor] + # [--vmm firecracker|cloud-hypervisor] [--nested] # The guest gets the directory xchg (in the current working directory) # at /xchg, via 9P over vsock. VMs started in the same directory share # it. Its store is read-only, unless it has nix (layers/nix.nix). @@ -577,11 +586,14 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' # --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). + # --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. set -efu export PATH=${lib.makeBinPath [ pkgs.coreutils pkgs.e2fsprogs pkgs.findutils pkgs.gnugrep pkgs.gnused pkgs.jq pkgs.openssh pkgs.util-linux pkgs.firecracker pkgs.cloud-hypervisor pkgs.git pkgs.socat pkgs.unpfs ]} usage() { - echo "usage: $0 [--store FILE] [--store-size SIZE] [--home FILE] [--home-size SIZE] [--mem-size MIB] [--nixpkgs DIR] [--nixpkgs-cache MODE] [--egress LIST] [--name NAME] [--vcpus N] [--secret NAME=FILE]... [--vmm firecracker|cloud-hypervisor]" + echo "usage: $0 [--store FILE] [--store-size SIZE] [--home FILE] [--home-size SIZE] [--mem-size MIB] [--nixpkgs DIR] [--nixpkgs-cache MODE] [--egress LIST] [--name NAME] [--vcpus N] [--secret NAME=FILE]... [--vmm firecracker|cloud-hypervisor] [--nested]" } args= rw_store= @@ -593,6 +605,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' name= vcpus=2 vmm=firecracker + nested= nixpkgs=${lib.escapeShellArg (toString pkgs.path)} nixpkgs_cache= nix_opt= # the last option that's only for a guest with nix @@ -613,6 +626,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' --vcpus) vcpus=$2; shift 2 ;; --secret) secrets+=("$2"); shift 2 ;; --vmm) vmm=$2; shift 2 ;; + --nested) nested=on; shift ;; -h|--help) usage; exit ;; *) usage >&2; exit 1 esac @@ -909,10 +923,11 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' -e "s|@RW_STORE@|$rw_store|" \ -e "s|@HOME@|$home|" \ ${config} | - jq --argjson vcpus "$vcpus" --argjson mem_size "$mem_size" --arg home "$home" ' + jq --argjson vcpus "$vcpus" --argjson mem_size "$mem_size" --arg home "$home" --arg nested "$nested" ' ."machine-config".vcpu_count = $vcpus | ."machine-config".mem_size_mib = $mem_size | - if $home == "" then del(.drives[] | select(.drive_id == "home")) end + if $home == "" then del(.drives[] | select(.drive_id == "home")) end | + if $nested != "" then del(."cpu-config") end ' > "$tmp"/config.json status=0 case $vmm in @@ -931,7 +946,7 @@ pkgs.writeShellScriptBin "run-firecracker-vm" /* sh */ '' --kernel "$(get '."boot-source".kernel_image_path')" \ --initramfs "$(get '."boot-source".initrd_path')" \ --cmdline "$(get '."boot-source".boot_args')" \ - --cpus boot="$vcpus" --memory size="$mem_size"M \ + --cpus boot="$vcpus",nested="''${nested:-off}" --memory size="$mem_size"M \ --disk "''${disks[@]}" \ --net tap="$tap",mac="$mac" \ --vsock cid=3,socket="$vsock" \ |
