1import ./make-test-python.nix ({ lib, pkgs, ... }: {
2 name = "systemd-initrd-btrfs-raid";
3
4 nodes.machine = { pkgs, ... }: {
5 # Use systemd-boot
6 virtualisation = {
7 emptyDiskImages = [ 512 512 ];
8 useBootLoader = true;
9 # Booting off the BTRFS RAID requires an available init script from the Nix store
10 mountHostNixStore = true;
11 useEFIBoot = true;
12 };
13 boot.loader.systemd-boot.enable = true;
14 boot.loader.efi.canTouchEfiVariables = true;
15
16 environment.systemPackages = with pkgs; [ btrfs-progs ];
17 boot.initrd.systemd = {
18 enable = true;
19 emergencyAccess = true;
20 };
21
22 specialisation.boot-btrfs-raid.configuration = {
23 fileSystems = lib.mkVMOverride {
24 "/".fsType = lib.mkForce "btrfs";
25 };
26 virtualisation.rootDevice = "/dev/vdb";
27 };
28 };
29
30 testScript = ''
31 # Create RAID
32 machine.succeed("mkfs.btrfs -d raid0 /dev/vdb /dev/vdc")
33 machine.succeed("mkdir -p /mnt && mount /dev/vdb /mnt && echo hello > /mnt/test && umount /mnt")
34
35 # Boot from the RAID
36 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-btrfs-raid.conf")
37 machine.succeed("sync")
38 machine.crash()
39 machine.wait_for_unit("multi-user.target")
40
41 # Ensure we have successfully booted from the RAID
42 assert "(initrd)" in machine.succeed("systemd-analyze") # booted with systemd in stage 1
43 assert "/dev/vdb on / type btrfs" in machine.succeed("mount")
44 assert "hello" in machine.succeed("cat /test")
45 assert "Total devices 2" in machine.succeed("btrfs filesystem show")
46 '';
47})