1 import ./make-test-python.nix ({ lib, pkgs, ... }: {
2 name = "systemd-initrd-swraid";
4 nodes.machine = { pkgs, ... }: {
7 emptyDiskImages = [ 512 512 ];
9 # Booting off the RAID requires an available init script
10 mountHostNixStore = true;
13 boot.loader.systemd-boot.enable = true;
14 boot.loader.efi.canTouchEfiVariables = true;
16 environment.systemPackages = with pkgs; [ mdadm e2fsprogs ]; # for mdadm and mkfs.ext4
20 ARRAY /dev/md0 devices=/dev/vdb,/dev/vdc
23 environment.etc."mdadm.conf".text = ''
24 MAILADDR test@example.com
29 emergencyAccess = true;
31 kernelModules = [ "raid0" ];
34 specialisation.boot-swraid.configuration.virtualisation.rootDevice = "/dev/disk/by-label/testraid";
35 # This protects against a regression. We do not have to switch to it.
36 # It's sufficient to trigger its evaluation.
37 specialisation.build-old-initrd.configuration.boot.initrd.systemd.enable = lib.mkForce false;
42 machine.succeed("mdadm --create --force /dev/md0 -n 2 --level=raid1 /dev/vdb /dev/vdc --metadata=0.90")
43 machine.succeed("mkfs.ext4 -L testraid /dev/md0")
44 machine.succeed("mkdir -p /mnt && mount /dev/md0 /mnt && echo hello > /mnt/test && umount /mnt")
47 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-swraid.conf")
48 machine.succeed("sync")
50 machine.wait_for_unit("multi-user.target")
52 # Ensure we have successfully booted from the RAID
53 assert "(initrd)" in machine.succeed("systemd-analyze") # booted with systemd in stage 1
54 assert "/dev/md0 on / type ext4" in machine.succeed("mount")
55 assert "hello" in machine.succeed("cat /test")
56 assert "md0" in machine.succeed("cat /proc/mdstat")
58 expected_config = """MAILADDR test@example.com
60 ARRAY /dev/md0 devices=/dev/vdb,/dev/vdc
62 got_config = machine.execute("cat /etc/mdadm.conf")[1]
63 assert expected_config == got_config, repr((expected_config, got_config))
64 machine.wait_for_unit("mdmonitor.service")