summary refs log tree commit diff
path: root/nixos/tests/efi-installer.nix
blob: 990f2b84a6c9d4ec2faeedc723fbaedb2eafa1f9 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# !!! Merge into normal install tests once all livecds are EFIable
{ pkgs, system, ... }:

with pkgs.lib;
with import ../lib/qemu-flags.nix;

let

  # Build the ISO.  This is the regular installation CD but with test
  # instrumentation.
  iso =
    (import ../lib/eval-config.nix {
      inherit system;
      modules =
        [ ../modules/installer/cd-dvd/installation-cd-minimal.nix
          ../modules/testing/test-instrumentation.nix
          { key = "serial";

            # The test cannot access the network, so any sources we
            # need must be included in the ISO.
            isoImage.storeContents =
              [ pkgs.glibcLocales
                pkgs.sudo
                pkgs.docbook5
                pkgs.docbook5_xsl
                pkgs.grub
                pkgs.perlPackages.XMLLibXML
                pkgs.unionfs-fuse
                pkgs.gummiboot
                pkgs.libxslt
              ];
          }
        ];
    }).config.system.build.isoImage;


  # The config to install
  config = builtins.toFile "configuration.nix" ''
    { pkgs, ... }: {
      imports = [ ./hardware-configuration.nix <nixos/modules/testing/test-instrumentation.nix> ];
      boot.loader.grub.enable = false;
      boot.loader.efi.canTouchEfiVariables = true;
      boot.loader.gummiboot.enable = true;
      fonts.enableFontConfig = false;
    }
  '';

  biosDir = pkgs.runCommand "ovmf-bios" {} ''
    mkdir $out
    ln -s ${pkgs.OVMF}/FV/OVMF.fd $out/bios.bin
  '';

in {
  simple = {
    inherit iso;
    nodes = {};
    testScript = ''
      createDisk("harddisk", 4 * 1024);

      my $machine = createMachine({ hda => "harddisk",
        hdaInterface => "scsi",
        cdrom => glob("${iso}/iso/*.iso"),
        qemuFlags => '-L ${biosDir} ${optionalString (pkgs.stdenv.system == "x86_64-linux") "-cpu kvm64"}'});
      $machine->start;

      # Make sure that we get a login prompt etc.
      $machine->succeed("echo hello");
      $machine->waitForUnit("rogue");
      $machine->waitForUnit("nixos-manual");

      # Partition the disk.
      $machine->succeed(
          "sgdisk -Z /dev/sda",
          "sgdisk -n 1:0:+256M -N 2 -t 1:ef00 -t 2:8300 -c 1:boot -c 2:root /dev/sda",
          "mkfs.vfat -n BOOT /dev/sda1",
          "mkfs.ext3 -L nixos /dev/sda2",
          "mount LABEL=nixos /mnt",
          "mkdir /mnt/boot",
          "mount LABEL=BOOT /mnt/boot",
      );

      # Create the NixOS configuration.
      $machine->succeed(
          "nixos-generate-config --root /mnt",
      );

      $machine->succeed("cat /mnt/etc/nixos/hardware-configuration.nix >&2");

      $machine->copyFileFromHost(
          "${config}",
          "/mnt/etc/nixos/configuration.nix");

      # Perform the installation.
      $machine->succeed("nixos-install >&2");

      # Do it again to make sure it's idempotent.
      $machine->succeed("nixos-install >&2");

      $machine->shutdown;

      # Now see if we can boot the installation.
      my $machine = createMachine({ #hda => "harddisk",
#       hdaInterface => "virtio",
#       !!! OVMF doesn't boot from virtio http://www.mail-archive.com/edk2-devel@lists.sourceforge.net/msg01501.html
        qemuFlags => '-L ${biosDir} ${optionalString (pkgs.stdenv.system == "x86_64-linux") "-cpu kvm64"} -m 512 -hda ' . Cwd::abs_path('harddisk')});

      # Did /boot get mounted, if appropriate?
      $machine->waitForUnit("local-fs.target");
      $machine->succeed("test -e /boot/efi");

      $machine->succeed("nix-env -i coreutils >&2");
      $machine->succeed("type -tP ls | tee /dev/stderr") =~ /.nix-profile/
          or die "nix-env failed";

      $machine->succeed("nixos-rebuild switch >&2");

      $machine->shutdown;

      my $machine = createMachine({ #hda => "harddisk",
#       hdaInterface => "virtio",
        qemuFlags => '-L ${biosDir} ${optionalString (pkgs.stdenv.system == "x86_64-linux") "-cpu kvm64"} -hda ' . Cwd::abs_path('harddisk')});
      $machine->waitForUnit("network.target");
      $machine->shutdown;
    '';
  };
}