2018-11-11 11:41:11 +03:00
|
|
|
{ system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../.. { inherit system config; }
|
|
|
|
}:
|
2017-11-13 21:56:03 +03:00
|
|
|
|
2020-01-28 10:54:17 +03:00
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
2017-11-13 21:56:03 +03:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
makeZfsTest = name:
|
2022-09-16 15:52:54 +03:00
|
|
|
{ kernelPackage ? if enableUnstable
|
|
|
|
then pkgs.zfsUnstable.latestCompatibleLinuxPackages
|
|
|
|
else pkgs.linuxPackages
|
2017-11-13 21:56:03 +03:00
|
|
|
, enableUnstable ? false
|
2023-03-27 15:25:08 +03:00
|
|
|
, enableSystemdStage1 ? false
|
2017-11-13 21:56:03 +03:00
|
|
|
, extraTest ? ""
|
|
|
|
}:
|
|
|
|
makeTest {
|
|
|
|
name = "zfs-" + name;
|
2021-01-10 22:08:30 +03:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2022-12-25 02:33:57 +03:00
|
|
|
maintainers = [ adisbladis elvishjerricco ];
|
2017-11-13 21:56:03 +03:00
|
|
|
};
|
|
|
|
|
2022-03-21 02:15:30 +03:00
|
|
|
nodes.machine = { pkgs, lib, ... }:
|
2021-06-11 09:24:56 +03:00
|
|
|
let
|
|
|
|
usersharePath = "/var/lib/samba/usershares";
|
|
|
|
in {
|
2022-12-25 02:33:57 +03:00
|
|
|
virtualisation = {
|
2022-12-25 02:36:26 +03:00
|
|
|
emptyDiskImages = [ 4096 4096 ];
|
2022-12-25 02:33:57 +03:00
|
|
|
useBootLoader = true;
|
|
|
|
useEFIBoot = true;
|
|
|
|
};
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
boot.loader.timeout = 0;
|
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
2020-01-28 10:54:17 +03:00
|
|
|
networking.hostId = "deadbeef";
|
|
|
|
boot.kernelPackages = kernelPackage;
|
|
|
|
boot.supportedFilesystems = [ "zfs" ];
|
|
|
|
boot.zfs.enableUnstable = enableUnstable;
|
2023-03-27 15:25:08 +03:00
|
|
|
boot.initrd.systemd.enable = enableSystemdStage1;
|
2017-11-13 21:56:03 +03:00
|
|
|
|
2022-12-25 02:33:57 +03:00
|
|
|
environment.systemPackages = [ pkgs.parted ];
|
|
|
|
|
|
|
|
# /dev/disk/by-id doesn't get populated in the NixOS test framework
|
|
|
|
boot.zfs.devNodes = "/dev/disk/by-uuid";
|
|
|
|
|
|
|
|
specialisation.samba.configuration = {
|
|
|
|
services.samba = {
|
|
|
|
enable = true;
|
|
|
|
extraConfig = ''
|
|
|
|
registry shares = yes
|
|
|
|
usershare path = ${usersharePath}
|
|
|
|
usershare allow guests = yes
|
|
|
|
usershare max shares = 100
|
|
|
|
usershare owner only = no
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
systemd.services.samba-smbd.serviceConfig.ExecStartPre =
|
|
|
|
"${pkgs.coreutils}/bin/mkdir -m +t -p ${usersharePath}";
|
|
|
|
virtualisation.fileSystems = {
|
|
|
|
"/tmp/mnt" = {
|
|
|
|
device = "rpool/root";
|
|
|
|
fsType = "zfs";
|
|
|
|
};
|
|
|
|
};
|
2021-06-11 09:24:56 +03:00
|
|
|
};
|
|
|
|
|
2022-12-25 02:33:57 +03:00
|
|
|
specialisation.encryption.configuration = {
|
2022-12-25 02:36:26 +03:00
|
|
|
boot.zfs.requestEncryptionCredentials = [ "automatic" ];
|
2022-12-25 02:33:57 +03:00
|
|
|
virtualisation.fileSystems."/automatic" = {
|
|
|
|
device = "automatic";
|
|
|
|
fsType = "zfs";
|
|
|
|
};
|
2022-12-25 02:36:26 +03:00
|
|
|
virtualisation.fileSystems."/manual" = {
|
|
|
|
device = "manual";
|
|
|
|
fsType = "zfs";
|
|
|
|
};
|
|
|
|
virtualisation.fileSystems."/manual/encrypted" = {
|
|
|
|
device = "manual/encrypted";
|
|
|
|
fsType = "zfs";
|
|
|
|
options = [ "noauto" ];
|
|
|
|
};
|
2023-04-18 17:44:25 +03:00
|
|
|
virtualisation.fileSystems."/manual/httpkey" = {
|
|
|
|
device = "manual/httpkey";
|
|
|
|
fsType = "zfs";
|
|
|
|
options = [ "noauto" ];
|
|
|
|
};
|
2022-12-25 02:33:57 +03:00
|
|
|
};
|
2020-08-18 16:05:22 +03:00
|
|
|
|
2022-12-25 02:33:57 +03:00
|
|
|
specialisation.forcepool.configuration = {
|
|
|
|
systemd.services.zfs-import-forcepool.wantedBy = lib.mkVMOverride [ "forcepool.mount" ];
|
|
|
|
systemd.targets.zfs.wantedBy = lib.mkVMOverride [];
|
|
|
|
boot.zfs.forceImportAll = true;
|
|
|
|
virtualisation.fileSystems."/forcepool" = {
|
2020-08-18 16:05:22 +03:00
|
|
|
device = "forcepool";
|
|
|
|
fsType = "zfs";
|
|
|
|
options = [ "noauto" ];
|
|
|
|
};
|
|
|
|
};
|
2023-04-18 17:44:25 +03:00
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts = {
|
|
|
|
localhost = {
|
|
|
|
locations = {
|
|
|
|
"/zfskey" = {
|
|
|
|
return = ''200 "httpkeyabc"'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-01-28 10:54:17 +03:00
|
|
|
};
|
2017-11-13 21:56:03 +03:00
|
|
|
|
|
|
|
testScript = ''
|
2022-12-25 02:33:57 +03:00
|
|
|
machine.wait_for_unit("multi-user.target")
|
2019-10-27 15:53:36 +03:00
|
|
|
machine.succeed(
|
2020-01-28 10:54:17 +03:00
|
|
|
"zpool status",
|
2022-10-16 01:18:03 +03:00
|
|
|
"parted --script /dev/vdb mklabel msdos",
|
|
|
|
"parted --script /dev/vdb -- mkpart primary 1024M -1s",
|
2022-12-25 02:33:57 +03:00
|
|
|
"parted --script /dev/vdc mklabel msdos",
|
|
|
|
"parted --script /dev/vdc -- mkpart primary 1024M -1s",
|
2019-10-27 15:53:36 +03:00
|
|
|
)
|
2020-02-19 22:38:15 +03:00
|
|
|
|
2022-12-25 02:33:57 +03:00
|
|
|
with subtest("sharesmb works"):
|
|
|
|
machine.succeed(
|
2022-10-16 01:18:03 +03:00
|
|
|
"zpool create rpool /dev/vdb1",
|
2022-12-25 02:33:57 +03:00
|
|
|
"zfs create -o mountpoint=legacy rpool/root",
|
|
|
|
# shared datasets cannot have legacy mountpoint
|
|
|
|
"zfs create rpool/shared_smb",
|
|
|
|
"bootctl set-default nixos-generation-1-specialisation-samba.conf",
|
|
|
|
"sync",
|
|
|
|
)
|
|
|
|
machine.crash()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
2023-09-16 17:06:58 +03:00
|
|
|
machine.succeed("zfs set sharesmb=on rpool/shared_smb")
|
2022-12-25 02:33:57 +03:00
|
|
|
machine.succeed(
|
|
|
|
"smbclient -gNL localhost | grep rpool_shared_smb",
|
|
|
|
"umount /tmp/mnt",
|
|
|
|
"zpool destroy rpool",
|
|
|
|
)
|
|
|
|
|
|
|
|
with subtest("encryption works"):
|
|
|
|
machine.succeed(
|
|
|
|
'echo password | zpool create -O mountpoint=legacy '
|
2022-10-16 01:18:03 +03:00
|
|
|
+ "-O encryption=aes-256-gcm -O keyformat=passphrase automatic /dev/vdb1",
|
|
|
|
"zpool create -O mountpoint=legacy manual /dev/vdc1",
|
2022-12-25 02:36:26 +03:00
|
|
|
"echo otherpass | zfs create "
|
|
|
|
+ "-o encryption=aes-256-gcm -o keyformat=passphrase manual/encrypted",
|
2023-04-18 17:44:25 +03:00
|
|
|
"zfs create -o encryption=aes-256-gcm -o keyformat=passphrase "
|
|
|
|
+ "-o keylocation=http://localhost/zfskey manual/httpkey",
|
2022-12-25 02:33:57 +03:00
|
|
|
"bootctl set-default nixos-generation-1-specialisation-encryption.conf",
|
|
|
|
"sync",
|
|
|
|
"zpool export automatic",
|
2022-12-25 02:36:26 +03:00
|
|
|
"zpool export manual",
|
2022-12-25 02:33:57 +03:00
|
|
|
)
|
|
|
|
machine.crash()
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_console_text("Starting password query on")
|
|
|
|
machine.send_console("password\n")
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
machine.succeed(
|
2023-04-18 17:44:25 +03:00
|
|
|
"zfs get -Ho value keystatus manual/encrypted | grep -Fx unavailable",
|
2022-12-25 02:36:26 +03:00
|
|
|
"echo otherpass | zfs load-key manual/encrypted",
|
|
|
|
"systemctl start manual-encrypted.mount",
|
2023-04-18 17:44:25 +03:00
|
|
|
"zfs load-key manual/httpkey",
|
|
|
|
"systemctl start manual-httpkey.mount",
|
|
|
|
"umount /automatic /manual/encrypted /manual/httpkey /manual",
|
2022-12-25 02:33:57 +03:00
|
|
|
"zpool destroy automatic",
|
2022-12-25 02:36:26 +03:00
|
|
|
"zpool destroy manual",
|
2022-12-25 02:33:57 +03:00
|
|
|
)
|
2020-08-18 16:05:22 +03:00
|
|
|
|
|
|
|
with subtest("boot.zfs.forceImportAll works"):
|
|
|
|
machine.succeed(
|
|
|
|
"rm /etc/hostid",
|
|
|
|
"zgenhostid deadcafe",
|
2022-10-16 01:18:03 +03:00
|
|
|
"zpool create forcepool /dev/vdb1 -O mountpoint=legacy",
|
2022-12-25 02:33:57 +03:00
|
|
|
"bootctl set-default nixos-generation-1-specialisation-forcepool.conf",
|
|
|
|
"rm /etc/hostid",
|
|
|
|
"sync",
|
2020-08-18 16:05:22 +03:00
|
|
|
)
|
2022-12-25 02:33:57 +03:00
|
|
|
machine.crash()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
2020-08-18 16:05:22 +03:00
|
|
|
machine.fail("zpool import forcepool")
|
|
|
|
machine.succeed(
|
2022-12-25 02:33:57 +03:00
|
|
|
"systemctl start forcepool.mount",
|
|
|
|
"mount | grep forcepool",
|
2020-08-18 16:05:22 +03:00
|
|
|
)
|
2017-11-13 21:56:03 +03:00
|
|
|
'' + extraTest;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
stable = makeZfsTest "stable" { };
|
|
|
|
|
|
|
|
unstable = makeZfsTest "unstable" {
|
|
|
|
enableUnstable = true;
|
|
|
|
};
|
|
|
|
|
2023-03-27 15:25:08 +03:00
|
|
|
unstableWithSystemdStage1 = makeZfsTest "unstable" {
|
|
|
|
enableUnstable = true;
|
|
|
|
enableSystemdStage1 = true;
|
|
|
|
};
|
|
|
|
|
2017-11-13 21:56:03 +03:00
|
|
|
installer = (import ./installer.nix { }).zfsroot;
|
2022-04-07 20:03:47 +03:00
|
|
|
|
|
|
|
expand-partitions = makeTest {
|
|
|
|
name = "multi-disk-zfs";
|
|
|
|
nodes = {
|
|
|
|
machine = { pkgs, ... }: {
|
|
|
|
environment.systemPackages = [ pkgs.parted ];
|
|
|
|
boot.supportedFilesystems = [ "zfs" ];
|
|
|
|
networking.hostId = "00000000";
|
|
|
|
|
|
|
|
virtualisation = {
|
|
|
|
emptyDiskImages = [ 20480 20480 20480 20480 20480 20480 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
specialisation.resize.configuration = {
|
|
|
|
services.zfs.expandOnBoot = [ "tank" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = { nodes, ... }:
|
|
|
|
''
|
|
|
|
start_all()
|
|
|
|
machine.wait_for_unit("default.target")
|
|
|
|
print(machine.succeed('mount'))
|
|
|
|
|
|
|
|
print(machine.succeed('parted --script /dev/vdb -- mklabel gpt'))
|
|
|
|
print(machine.succeed('parted --script /dev/vdb -- mkpart primary 1M 70M'))
|
|
|
|
|
|
|
|
print(machine.succeed('parted --script /dev/vdc -- mklabel gpt'))
|
|
|
|
print(machine.succeed('parted --script /dev/vdc -- mkpart primary 1M 70M'))
|
|
|
|
|
|
|
|
print(machine.succeed('zpool create tank mirror /dev/vdb1 /dev/vdc1 mirror /dev/vdd /dev/vde mirror /dev/vdf /dev/vdg'))
|
|
|
|
print(machine.succeed('zpool list -v'))
|
|
|
|
print(machine.succeed('mount'))
|
|
|
|
start_size = int(machine.succeed('df -k --output=size /tank | tail -n1').strip())
|
|
|
|
|
|
|
|
print(machine.succeed("/run/current-system/specialisation/resize/bin/switch-to-configuration test >&2"))
|
|
|
|
machine.wait_for_unit("zpool-expand-pools.service")
|
|
|
|
machine.wait_for_unit("zpool-expand@tank.service")
|
|
|
|
|
|
|
|
print(machine.succeed('zpool list -v'))
|
|
|
|
new_size = int(machine.succeed('df -k --output=size /tank | tail -n1').strip())
|
|
|
|
|
|
|
|
if (new_size - start_size) > 20000000:
|
|
|
|
print("Disk grew appropriately.")
|
|
|
|
else:
|
|
|
|
print(f"Disk went from {start_size} to {new_size}, which doesn't seem right.")
|
|
|
|
exit(1)
|
|
|
|
'';
|
|
|
|
};
|
2017-11-13 21:56:03 +03:00
|
|
|
}
|