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 useEFIBoot = true;
10 };
11 boot.loader.systemd-boot.enable = true;
12 boot.loader.efi.canTouchEfiVariables = true;
13
14 environment.systemPackages = with pkgs; [ btrfs-progs ];
15 boot.initrd.systemd = {
16 enable = true;
17 emergencyAccess = true;
18 };
19
20 specialisation.boot-btrfs-raid.configuration = {
21 fileSystems = lib.mkVMOverride {
22 "/".fsType = lib.mkForce "btrfs";
23 };
24 virtualisation.bootDevice = "/dev/vdc";
25 };
26 };
27
28 testScript = ''
29 # Create RAID
30 machine.succeed("mkfs.btrfs -d raid0 /dev/vdc /dev/vdd")
31 machine.succeed("mkdir -p /mnt && mount /dev/vdc /mnt && echo hello > /mnt/test && umount /mnt")
32
33 # Boot from the RAID
34 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-btrfs-raid.conf")
35 machine.succeed("sync")
36 machine.crash()
37 machine.wait_for_unit("multi-user.target")
38
39 # Ensure we have successfully booted from the RAID
40 assert "(initrd)" in machine.succeed("systemd-analyze") # booted with systemd in stage 1
41 assert "/dev/vdc on / type btrfs" in machine.succeed("mount")
42 assert "hello" in machine.succeed("cat /test")
43 assert "Total devices 2" in machine.succeed("btrfs filesystem show")
44 '';
45})