summary refs log tree commit diff
path: root/img/installer/run-vm.nix
blob: ac6e92883c307113588a2981f9040758158b0aaf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2021-2022 Alyssa Ross <hi@alyssa.is>

{ pkgs ? import <nixpkgs> {} }:

let
  inherit (builtins) storeDir;
  inherit (pkgs) coreutils qemu_kvm writeShellScript;
  inherit (pkgs.lib) makeBinPath escapeShellArg;

  eosimages = import ../combined/eosimages.nix { inherit pkgs; };

  installer = import ./. {
    inherit pkgs;

    extraConfig = {
      boot.initrd.availableKernelModules = [ "9p" "9pnet_virtio" ];

      fileSystems.${storeDir} = {
        fsType = "9p";
        device = "store";
        # This can be removed when running Linux ≥5.15.
        options = [ "msize=131072" ];
      };
    };
  };
in

writeShellScript "run-spectrum-installer-vm.sh" ''
  export PATH=${makeBinPath [ coreutils qemu_kvm ]}
  img="$(mktemp spectrum-installer-target.XXXXXXXXXX.img)"
  truncate -s 10G "$img"
  exec 3<>"$img"
  rm -f "$img"
  exec qemu-kvm -cpu host -m 4G -machine q35 -snapshot \
    -display gtk,gl=on \
    -device virtio-vga-gl \
    -virtfs local,mount_tag=store,path=/nix/store,security_model=none,readonly=true \
    -drive file=${qemu_kvm}/share/qemu/edk2-${stdenv.hostPlatform.qemuArch}-code.fd,format=raw,if=pflash,readonly=true \
    -drive file=${eosimages},format=raw,if=virtio,readonly=true \
    -drive file=/proc/self/fd/3,format=raw,if=virtio \
    -kernel ${installer.kernel} \
    -initrd ${installer.initramfs} \
    -append ${escapeShellArg installer.kernelParams}
''