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 bind = makeTest {
10 name = "non-default-filesystem-bind";
11
12 nodes.machine = { ... }: {
13 virtualisation.writableStore = false;
14
15 virtualisation.fileSystems."/test-bind-dir/bind" = {
16 device = "/";
17 neededForBoot = true;
18 options = [ "bind" ];
19 };
20
21 virtualisation.fileSystems."/test-bind-file/bind" = {
22 depends = [ "/nix/store" ];
23 device = builtins.toFile "empty" "";
24 neededForBoot = true;
25 options = [ "bind" ];
26 };
27 };
28
29 testScript = ''
30 machine.wait_for_unit("multi-user.target")
31 '';
32 };
33
34 btrfs = makeTest
35 {
36 name = "non-default-filesystems-btrfs";
37
38 nodes.machine =
39 { config, pkgs, lib, ... }:
40 let
41 disk = config.virtualisation.rootDevice;
42 in
43 {
44 virtualisation.rootDevice = "/dev/vda";
45 virtualisation.useDefaultFilesystems = false;
46
47 boot.initrd.availableKernelModules = [ "btrfs" ];
48 boot.supportedFilesystems = [ "btrfs" ];
49
50 boot.initrd.postDeviceCommands = ''
51 FSTYPE=$(blkid -o value -s TYPE ${disk} || true)
52 if test -z "$FSTYPE"; then
53 modprobe btrfs
54 ${pkgs.btrfs-progs}/bin/mkfs.btrfs ${disk}
55
56 mkdir /nixos
57 mount -t btrfs ${disk} /nixos
58
59 ${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/root
60 ${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/home
61
62 umount /nixos
63 fi
64 '';
65
66 virtualisation.fileSystems = {
67 "/" = {
68 device = disk;
69 fsType = "btrfs";
70 options = [ "subvol=/root" ];
71 };
72
73 "/home" = {
74 device = disk;
75 fsType = "btrfs";
76 options = [ "subvol=/home" ];
77 };
78 };
79 };
80
81 testScript = ''
82 machine.wait_for_unit("multi-user.target")
83
84 with subtest("BTRFS filesystems are mounted correctly"):
85 machine.succeed("grep -E '/dev/vda / btrfs rw,relatime,space_cache=v2,subvolid=[0-9]+,subvol=/root 0 0' /proc/mounts")
86 machine.succeed("grep -E '/dev/vda /home btrfs rw,relatime,space_cache=v2,subvolid=[0-9]+,subvol=/home 0 0' /proc/mounts")
87 '';
88 };
89
90 erofs =
91 let
92 fsImage = "/tmp/non-default-filesystem.img";
93 in
94 makeTest {
95 name = "non-default-filesystems-erofs";
96
97 meta.maintainers = with maintainers; [ nikstur ];
98
99 nodes.machine = _: {
100 virtualisation.qemu.drives = [{
101 name = "non-default-filesystem";
102 file = fsImage;
103 }];
104
105 virtualisation.fileSystems."/non-default" = {
106 device = "/dev/vdb";
107 fsType = "erofs";
108 neededForBoot = true;
109 };
110 };
111
112 testScript = ''
113 import subprocess
114 import tempfile
115
116 with tempfile.TemporaryDirectory() as tmp_dir:
117 with open(f"{tmp_dir}/filesystem", "w") as f:
118 f.write("erofs")
119
120 subprocess.run([
121 "${pkgs.erofs-utils}/bin/mkfs.erofs",
122 "${fsImage}",
123 tmp_dir,
124 ])
125
126 machine.start()
127 machine.wait_for_unit("default.target")
128
129 file_contents = machine.succeed("cat /non-default/filesystem")
130 assert "erofs" in file_contents
131 '';
132 };
133
134 squashfs =
135 let
136 fsImage = "/tmp/non-default-filesystem.img";
137 in
138 makeTest {
139 name = "non-default-filesystems-squashfs";
140
141 meta.maintainers = with maintainers; [ nikstur ];
142
143 nodes.machine = {
144 virtualisation.qemu.drives = [{
145 name = "non-default-filesystem";
146 file = fsImage;
147 deviceExtraOpts.serial = "non-default";
148 }];
149
150 virtualisation.fileSystems."/non-default" = {
151 device = "/dev/disk/by-id/virtio-non-default";
152 fsType = "squashfs";
153 neededForBoot = true;
154 };
155 };
156
157 testScript = ''
158 import subprocess
159
160 with open("filesystem", "w") as f:
161 f.write("squashfs")
162
163 subprocess.run([
164 "${pkgs.squashfsTools}/bin/mksquashfs",
165 "filesystem",
166 "${fsImage}",
167 ])
168
169 assert "squashfs" in machine.succeed("cat /non-default/filesystem")
170 '';
171 };
172}