1{ system ? builtins.currentSystem
2, config ? { }
3, pkgs ? import ../.. { inherit system config; }
4}:
5
6with import ../lib/testing-python.nix { inherit system pkgs; };
7with pkgs.lib;
8{
9 btrfs = makeTest
10 {
11 name = "non-default-filesystems-btrfs";
12
13 nodes.machine =
14 { config, pkgs, lib, ... }:
15 let
16 disk = config.virtualisation.rootDevice;
17 in
18 {
19 virtualisation.rootDevice = "/dev/vda";
20 virtualisation.useDefaultFilesystems = false;
21
22 boot.initrd.availableKernelModules = [ "btrfs" ];
23 boot.supportedFilesystems = [ "btrfs" ];
24
25 boot.initrd.postDeviceCommands = ''
26 FSTYPE=$(blkid -o value -s TYPE ${disk} || true)
27 if test -z "$FSTYPE"; then
28 modprobe btrfs
29 ${pkgs.btrfs-progs}/bin/mkfs.btrfs ${disk}
30
31 mkdir /nixos
32 mount -t btrfs ${disk} /nixos
33
34 ${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/root
35 ${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/home
36
37 umount /nixos
38 fi
39 '';
40
41 virtualisation.fileSystems = {
42 "/" = {
43 device = disk;
44 fsType = "btrfs";
45 options = [ "subvol=/root" ];
46 };
47
48 "/home" = {
49 device = disk;
50 fsType = "btrfs";
51 options = [ "subvol=/home" ];
52 };
53 };
54 };
55
56 testScript = ''
57 machine.wait_for_unit("multi-user.target")
58
59 with subtest("BTRFS filesystems are mounted correctly"):
60 machine.succeed("grep -E '/dev/vda / btrfs rw,relatime,space_cache=v2,subvolid=[0-9]+,subvol=/root 0 0' /proc/mounts")
61 machine.succeed("grep -E '/dev/vda /home btrfs rw,relatime,space_cache=v2,subvolid=[0-9]+,subvol=/home 0 0' /proc/mounts")
62 '';
63 };
64
65 erofs =
66 let
67 fsImage = "/tmp/non-default-filesystem.img";
68 in
69 makeTest {
70 name = "non-default-filesystems-erofs";
71
72 nodes.machine = _: {
73 virtualisation.qemu.drives = [{
74 name = "non-default-filesystem";
75 file = fsImage;
76 }];
77
78 virtualisation.fileSystems."/non-default" = {
79 device = "/dev/vdb";
80 fsType = "erofs";
81 neededForBoot = true;
82 };
83 };
84
85 testScript = ''
86 import subprocess
87 import tempfile
88
89 with tempfile.TemporaryDirectory() as tmp_dir:
90 with open(f"{tmp_dir}/filesystem", "w") as f:
91 f.write("erofs")
92
93 subprocess.run([
94 "${pkgs.erofs-utils}/bin/mkfs.erofs",
95 "${fsImage}",
96 tmp_dir,
97 ])
98
99 machine.start()
100 machine.wait_for_unit("default.target")
101
102 file_contents = machine.succeed("cat /non-default/filesystem")
103 assert "erofs" in file_contents
104 '';
105 };
106}