summaryrefslogtreecommitdiffstats
path: root/nixos/tests/systemd-initrd-btrfs-raid.nix
blob: 05caa522b0d7166fe267ed04edd64532637e811b (plain)
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
{ lib, ... }:
{
  name = "systemd-initrd-btrfs-raid";

  nodes.machine =
    { pkgs, ... }:
    {
      # Use systemd-boot
      virtualisation = {
        emptyDiskImages = [
          512
          512
        ];
        useBootLoader = true;
        # Booting off the BTRFS RAID requires an available init script from the Nix store
        mountHostNixStore = true;
        useEFIBoot = true;
      };
      boot.loader.systemd-boot.enable = true;
      boot.loader.efi.canTouchEfiVariables = true;

      environment.systemPackages = with pkgs; [ btrfs-progs ];
      boot.initrd.systemd = {
        enable = true;
        emergencyAccess = true;
      };

      specialisation.boot-btrfs-raid.configuration = {
        fileSystems = lib.mkVMOverride {
          "/".fsType = lib.mkForce "btrfs";
        };
        virtualisation.rootDevice = "/dev/vdb";
      };
    };

  testScript =
    { nodes, ... }:
    let
      boot-btrfs-raid = nodes.machine.specialisation.boot-btrfs-raid.configuration.system.build.toplevel;
    in
    # python
    ''
      # Create RAID
      machine.succeed("mkfs.btrfs -d raid0 /dev/vdb /dev/vdc")
      machine.succeed("mkdir -p /mnt && mount /dev/vdb /mnt && echo hello > /mnt/test && umount /mnt")

      # Boot from the RAID
      machine.succeed("${boot-btrfs-raid}/bin/switch-to-configuration boot")
      machine.succeed("sync")
      machine.crash()
      machine.wait_for_unit("multi-user.target")

      # Ensure we have successfully booted from the RAID
      assert "(initrd)" in machine.succeed("systemd-analyze")  # booted with systemd in stage 1
      assert "/dev/vdb on / type btrfs" in machine.succeed("mount")
      assert "hello" in machine.succeed("cat /test")
      assert "Total devices 2" in machine.succeed("btrfs filesystem show")
    '';
}