1 { system ? builtins.currentSystem,
3 pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
11 { kernelPackage ? if enableUnstable
12 then pkgs.zfsUnstable.latestCompatibleLinuxPackages
13 else pkgs.linuxPackages
14 , enableUnstable ? false
19 meta = with pkgs.lib.maintainers; {
20 maintainers = [ adisbladis ];
23 nodes.machine = { pkgs, lib, ... }:
25 usersharePath = "/var/lib/samba/usershares";
27 virtualisation.emptyDiskImages = [ 4096 ];
28 networking.hostId = "deadbeef";
29 boot.kernelPackages = kernelPackage;
30 boot.supportedFilesystems = [ "zfs" ];
31 boot.zfs.enableUnstable = enableUnstable;
37 usershare path = ${usersharePath}
38 usershare allow guests = yes
39 usershare max shares = 100
40 usershare owner only = no
43 systemd.services.samba-smbd.serviceConfig.ExecStartPre =
44 "${pkgs.coreutils}/bin/mkdir -m +t -p ${usersharePath}";
46 environment.systemPackages = [ pkgs.parted ];
48 # Setup regular fileSystems machinery to ensure forceImportAll can be
49 # tested via the regular service units.
50 virtualisation.fileSystems = {
54 options = [ "noauto" ];
58 # forcepool doesn't exist at first boot, and we need to manually test
59 # the import after tweaking the hostId.
60 systemd.services.zfs-import-forcepool.wantedBy = lib.mkVMOverride [];
61 systemd.targets.zfs.wantedBy = lib.mkVMOverride [];
62 boot.zfs.forceImportAll = true;
63 # /dev/disk/by-id doesn't get populated in the NixOS test framework
64 boot.zfs.devNodes = "/dev/disk/by-uuid";
74 "parted --script /dev/vdb mklabel msdos",
75 "parted --script /dev/vdb -- mkpart primary 1024M -1s",
77 "zpool create rpool /dev/vdb1",
78 "zfs create -o mountpoint=legacy rpool/root",
79 # shared datasets cannot have legacy mountpoint
80 "zfs create rpool/shared_smb",
81 "mount -t zfs rpool/root /tmp/mnt",
83 # wait for samba services
84 "systemctl is-system-running --wait",
85 "zfs set sharesmb=on rpool/shared_smb",
86 "zfs share rpool/shared_smb",
87 "smbclient -gNL localhost | grep rpool_shared_smb",
89 "zpool destroy rpool",
94 'echo password | zpool create -o altroot="/tmp/mnt" '
95 + "-O encryption=aes-256-gcm -O keyformat=passphrase rpool /dev/vdb1",
96 "zfs create -o mountpoint=legacy rpool/root",
97 "mount -t zfs rpool/root /tmp/mnt",
100 "zpool destroy rpool",
104 with subtest("boot.zfs.forceImportAll works"):
107 "zgenhostid deadcafe",
108 "zpool create forcepool /dev/vdb1 -O mountpoint=legacy",
112 machine.succeed("udevadm settle")
113 machine.fail("zpool import forcepool")
115 "systemctl start zfs-import-forcepool.service",
116 "mount -t zfs forcepool /tmp/mnt",
125 stable = makeZfsTest "stable" { };
127 unstable = makeZfsTest "unstable" {
128 enableUnstable = true;
131 installer = (import ./installer.nix { }).zfsroot;
133 expand-partitions = makeTest {
134 name = "multi-disk-zfs";
136 machine = { pkgs, ... }: {
137 environment.systemPackages = [ pkgs.parted ];
138 boot.supportedFilesystems = [ "zfs" ];
139 networking.hostId = "00000000";
142 emptyDiskImages = [ 20480 20480 20480 20480 20480 20480 ];
145 specialisation.resize.configuration = {
146 services.zfs.expandOnBoot = [ "tank" ];
151 testScript = { nodes, ... }:
154 machine.wait_for_unit("default.target")
155 print(machine.succeed('mount'))
157 print(machine.succeed('parted --script /dev/vdb -- mklabel gpt'))
158 print(machine.succeed('parted --script /dev/vdb -- mkpart primary 1M 70M'))
160 print(machine.succeed('parted --script /dev/vdc -- mklabel gpt'))
161 print(machine.succeed('parted --script /dev/vdc -- mkpart primary 1M 70M'))
163 print(machine.succeed('zpool create tank mirror /dev/vdb1 /dev/vdc1 mirror /dev/vdd /dev/vde mirror /dev/vdf /dev/vdg'))
164 print(machine.succeed('zpool list -v'))
165 print(machine.succeed('mount'))
166 start_size = int(machine.succeed('df -k --output=size /tank | tail -n1').strip())
168 print(machine.succeed("/run/current-system/specialisation/resize/bin/switch-to-configuration test >&2"))
169 machine.wait_for_unit("zpool-expand-pools.service")
170 machine.wait_for_unit("zpool-expand@tank.service")
172 print(machine.succeed('zpool list -v'))
173 new_size = int(machine.succeed('df -k --output=size /tank | tail -n1').strip())
175 if (new_size - start_size) > 20000000:
176 print("Disk grew appropriately.")
178 print(f"Disk went from {start_size} to {new_size}, which doesn't seem right.")