1 { system ? builtins.currentSystem,
3 pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
12 , enableSystemdStage1 ? false
17 name = zfsPackage.kernelModuleAttribute;
18 meta = with pkgs.lib.maintainers; {
19 maintainers = [ elvishjerricco ];
22 nodes.machine = { config, pkgs, lib, ... }:
24 usersharePath = "/var/lib/samba/usershares";
27 emptyDiskImages = [ 4096 4096 ];
31 boot.loader.systemd-boot.enable = true;
32 boot.loader.timeout = 0;
33 boot.loader.efi.canTouchEfiVariables = true;
34 networking.hostId = "deadbeef";
35 boot.kernelPackages = kernelPackages;
36 boot.zfs.package = zfsPackage;
37 boot.supportedFilesystems = [ "zfs" ];
38 boot.initrd.systemd.enable = enableSystemdStage1;
40 environment.systemPackages = [ pkgs.parted ];
42 # /dev/disk/by-id doesn't get populated in the NixOS test framework
43 boot.zfs.devNodes = "/dev/disk/by-uuid";
45 specialisation.samba.configuration = {
49 "registry shares" = true;
50 "usershare path" = "${usersharePath}";
51 "usershare allow guests" = true;
52 "usershare max shares" = "100";
53 "usershare owner only" = false;
56 systemd.services.samba-smbd.serviceConfig.ExecStartPre =
57 "${pkgs.coreutils}/bin/mkdir -m +t -p ${usersharePath}";
58 virtualisation.fileSystems = {
60 device = "rpool/root";
66 specialisation.encryption.configuration = {
67 boot.zfs.requestEncryptionCredentials = [ "automatic" ];
68 virtualisation.fileSystems."/automatic" = {
72 virtualisation.fileSystems."/manual" = {
76 virtualisation.fileSystems."/manual/encrypted" = {
77 device = "manual/encrypted";
79 options = [ "noauto" ];
81 virtualisation.fileSystems."/manual/httpkey" = {
82 device = "manual/httpkey";
84 options = [ "noauto" ];
88 specialisation.forcepool.configuration = {
89 systemd.services.zfs-import-forcepool.wantedBy = lib.mkVMOverride [ "forcepool.mount" ];
90 systemd.targets.zfs.wantedBy = lib.mkVMOverride [];
91 boot.zfs.forceImportAll = true;
92 virtualisation.fileSystems."/forcepool" = {
95 options = [ "noauto" ];
105 return = ''200 "httpkeyabc"'';
114 machine.wait_for_unit("multi-user.target")
117 "parted --script /dev/vdb mklabel msdos",
118 "parted --script /dev/vdb -- mkpart primary 1024M -1s",
119 "parted --script /dev/vdc mklabel msdos",
120 "parted --script /dev/vdc -- mkpart primary 1024M -1s",
123 with subtest("sharesmb works"):
125 "zpool create rpool /dev/vdb1",
126 "zfs create -o mountpoint=legacy rpool/root",
127 # shared datasets cannot have legacy mountpoint
128 "zfs create rpool/shared_smb",
129 "bootctl set-default nixos-generation-1-specialisation-samba.conf",
133 machine.wait_for_unit("multi-user.target")
134 machine.succeed("zfs set sharesmb=on rpool/shared_smb")
136 "smbclient -gNL localhost | grep rpool_shared_smb",
138 "zpool destroy rpool",
141 with subtest("encryption works"):
143 'echo password | zpool create -O mountpoint=legacy '
144 + "-O encryption=aes-256-gcm -O keyformat=passphrase automatic /dev/vdb1",
145 "zpool create -O mountpoint=legacy manual /dev/vdc1",
146 "echo otherpass | zfs create "
147 + "-o encryption=aes-256-gcm -o keyformat=passphrase manual/encrypted",
148 "zfs create -o encryption=aes-256-gcm -o keyformat=passphrase "
149 + "-o keylocation=http://localhost/zfskey manual/httpkey",
150 "bootctl set-default nixos-generation-1-specialisation-encryption.conf",
152 "zpool export automatic",
153 "zpool export manual",
157 machine.wait_for_console_text("Starting password query on")
158 machine.send_console("password\n")
159 machine.wait_for_unit("multi-user.target")
161 "zfs get -Ho value keystatus manual/encrypted | grep -Fx unavailable",
162 "echo otherpass | zfs load-key manual/encrypted",
163 "systemctl start manual-encrypted.mount",
164 "zfs load-key manual/httpkey",
165 "systemctl start manual-httpkey.mount",
166 "umount /automatic /manual/encrypted /manual/httpkey /manual",
167 "zpool destroy automatic",
168 "zpool destroy manual",
171 with subtest("boot.zfs.forceImportAll works"):
174 "zgenhostid deadcafe",
175 "zpool create forcepool /dev/vdb1 -O mountpoint=legacy",
176 "bootctl set-default nixos-generation-1-specialisation-forcepool.conf",
181 machine.wait_for_unit("multi-user.target")
182 machine.fail("zpool import forcepool")
184 "systemctl start forcepool.mount",
185 "mount | grep forcepool",
194 # maintainer: @raitobezarius
195 series_2_1 = makeZfsTest {
196 zfsPackage = pkgs.zfs_2_1;
197 kernelPackages = pkgs.linuxPackages;
200 series_2_2 = makeZfsTest {
201 zfsPackage = pkgs.zfs_2_2;
202 kernelPackages = pkgs.linuxPackages;
205 unstable = makeZfsTest rec {
206 zfsPackage = pkgs.zfs_unstable;
207 kernelPackages = pkgs.linuxPackages;
210 unstableWithSystemdStage1 = makeZfsTest rec {
211 zfsPackage = pkgs.zfs_unstable;
212 kernelPackages = pkgs.linuxPackages;
213 enableSystemdStage1 = true;
216 installerBoot = (import ./installer.nix { inherit system; }).separateBootZfs;
217 installer = (import ./installer.nix { inherit system; }).zfsroot;
219 expand-partitions = makeTest {
220 name = "multi-disk-zfs";
222 machine = { pkgs, ... }: {
223 environment.systemPackages = [ pkgs.parted ];
224 boot.supportedFilesystems = [ "zfs" ];
225 networking.hostId = "00000000";
228 emptyDiskImages = [ 20480 20480 20480 20480 20480 20480 ];
231 specialisation.resize.configuration = {
232 services.zfs.expandOnBoot = [ "tank" ];
237 testScript = { nodes, ... }:
240 machine.wait_for_unit("default.target")
241 print(machine.succeed('mount'))
243 print(machine.succeed('parted --script /dev/vdb -- mklabel gpt'))
244 print(machine.succeed('parted --script /dev/vdb -- mkpart primary 1M 70M'))
246 print(machine.succeed('parted --script /dev/vdc -- mklabel gpt'))
247 print(machine.succeed('parted --script /dev/vdc -- mkpart primary 1M 70M'))
249 print(machine.succeed('zpool create tank mirror /dev/vdb1 /dev/vdc1 mirror /dev/vdd /dev/vde mirror /dev/vdf /dev/vdg'))
250 print(machine.succeed('zpool list -v'))
251 print(machine.succeed('mount'))
252 start_size = int(machine.succeed('df -k --output=size /tank | tail -n1').strip())
254 print(machine.succeed("/run/current-system/specialisation/resize/bin/switch-to-configuration test >&2"))
255 machine.wait_for_unit("zpool-expand-pools.service")
256 machine.wait_for_unit("zpool-expand@tank.service")
258 print(machine.succeed('zpool list -v'))
259 new_size = int(machine.succeed('df -k --output=size /tank | tail -n1').strip())
261 if (new_size - start_size) > 20000000:
262 print("Disk grew appropriately.")
264 print(f"Disk went from {start_size} to {new_size}, which doesn't seem right.")