summary refs log tree commit diff
path: root/nixos/tests/boot.nix
blob: 301d9d0f817f84fb760844c6682aeb50f7cf1b4d (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{ system ? builtins.currentSystem }:

with import ../lib/testing.nix { inherit system; };
with pkgs.lib;

let

  iso =
    (import ../lib/eval-config.nix {
      inherit system;
      modules =
        [ ../modules/installer/cd-dvd/installation-cd-minimal.nix
          ../modules/testing/test-instrumentation.nix
        ];
    }).config.system.build.isoImage;

  makeBootTest = name: machineConfig:
    makeTest {
      inherit iso;
      name = "boot-" + name;
      nodes = { };
      testScript =
        ''
          my $machine = createMachine({ ${machineConfig}, qemuFlags => '-m 768' });
          $machine->start;
          $machine->waitForUnit("multi-user.target");
          $machine->succeed("nix verify -r --no-trust /run/current-system");

          # Test whether the channel got installed correctly.
          $machine->succeed("nix-instantiate --dry-run '<nixpkgs>' -A hello");
          $machine->succeed("nix-env --dry-run -iA nixos.procps");

          $machine->shutdown;
        '';
    };
in {

    biosCdrom = makeBootTest "bios-cdrom" ''
        cdrom => glob("${iso}/iso/*.iso")
      '';

    biosUsb = makeBootTest "bios-usb" ''
        usb => glob("${iso}/iso/*.iso")
      '';

    uefiCdrom = makeBootTest "uefi-cdrom" ''
        cdrom => glob("${iso}/iso/*.iso"),
        bios => '${pkgs.OVMF.fd}/FV/OVMF.fd'
      '';

    uefiUsb = makeBootTest "uefi-usb" ''
        usb => glob("${iso}/iso/*.iso"),
        bios => '${pkgs.OVMF.fd}/FV/OVMF.fd'
      '';

    netboot = let
      config = (import ../lib/eval-config.nix {
          inherit system;
          modules =
            [ ../modules/installer/netboot/netboot.nix
              ../modules/testing/test-instrumentation.nix
              { key = "serial"; }
            ];
        }).config;
      ipxeScriptDir = pkgs.writeTextFile {
        name = "ipxeScriptDir";
        text = ''
          #!ipxe
          dhcp
          kernel bzImage init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} console=ttyS0
          initrd initrd
          boot
        '';
        destination = "/boot.ipxe";
      };
      ipxeBootDir = pkgs.symlinkJoin {
        name = "ipxeBootDir";
        paths = [
          config.system.build.netbootRamdisk
          config.system.build.kernel
          ipxeScriptDir
        ];
      };
    in
      makeTest {
        name = "boot-netboot";
        nodes = { };
        testScript =
          ''
            my $machine = createMachine({ qemuFlags => '-boot order=n -net nic,model=e1000 -net user,tftp=${ipxeBootDir}/,bootfile=boot.ipxe -m 2000M' });
            $machine->start;
            $machine->waitForUnit("multi-user.target");
            $machine->shutdown;
          '';
      };
}