-
Notifications
You must be signed in to change notification settings - Fork 0
/
zfs.nix
69 lines (63 loc) · 1.83 KB
/
zfs.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
pkgs,
nixos-lib,
nixosModule,
}:
nixos-lib.runTest {
name = "zfs";
hostPkgs = pkgs;
nodes.machine = {
pkgs,
lib,
...
}: {
imports = [
nixosModule
];
config = {
networking.hostId = "deadbea7";
virtualisation.useDefaultFilesystems = false;
virtualisation.rootDevice = "/dev/vda1";
boot.initrd.postDeviceCommands = ''
if ! test -b /dev/vda1; then
${pkgs.parted}/bin/parted --script /dev/vda -- mklabel msdos
${pkgs.parted}/bin/parted --script /dev/vda -- mkpart primary 1MiB 100%
sync
fi
if ! ${pkgs.zfs}/bin/zpool list test >/dev/null; then
${pkgs.zfs}/bin/zpool create test /dev/vda1
${pkgs.zfs}/bin/zfs create -o mountpoint=legacy -o canmount=on test/root
${pkgs.zfs}/bin/zfs create -o mountpoint=legacy -o canmount=on test/ephemeral
fi
'';
virtualisation.fileSystems = {
"/ephemeral" = {
# our test partition
device = "test/ephemeral";
fsType = "zfs";
};
"/" = {
device = "test/root";
fsType = "zfs";
};
};
preroll-safety.enable = true;
preroll-safety.stockChecks.enable = false;
preroll-safety.checks.zfs.enable = true;
virtualisation = {
cores = 2;
memorySize = 2048;
};
};
};
testScript = ''
machine.start()
machine.wait_for_unit("multi-user.target")
with subtest("Filesystems at boot are ok"):
machine.succeed("/run/current-system/pre-activate-safety-checks")
with subtest("Removing a filesystem causes the check to fail"):
machine.succeed("umount /ephemeral")
machine.succeed("${pkgs.zfs}/bin/zfs destroy test/ephemeral")
machine.fail("/run/current-system/pre-activate-safety-checks")
'';
}