diff --git a/example/zfs-with-vdevs.nix b/example/zfs-with-vdevs.nix index cd85add..0058ac5 100644 --- a/example/zfs-with-vdevs.nix +++ b/example/zfs-with-vdevs.nix @@ -60,7 +60,7 @@ }; cache = { type = "disk"; - device = "/dev/sdc"; + device = "/dev/vdc"; content = { type = "gpt"; partitions = { @@ -100,15 +100,14 @@ }; datasets = { - # See examples/zfs.nix for more comprehensive usage. - zfs_fs = { - type = "zfs_fs"; - mountpoint = "/zfs_fs"; - options."com.sun:auto-snapshot" = "true"; - }; + # See examples/zfs.nix for more comprehensive usage. + zfs_fs = { + type = "zfs_fs"; + mountpoint = "/zfs_fs"; + options."com.sun:auto-snapshot" = "true"; + }; }; }; }; }; } - diff --git a/example/zfs.nix b/example/zfs.nix index 933386a..4d09061 100644 --- a/example/zfs.nix +++ b/example/zfs.nix @@ -100,4 +100,3 @@ }; }; } - diff --git a/lib/types/zpool.nix b/lib/types/zpool.nix index d3fcda4..b7e35d3 100644 --- a/lib/types/zpool.nix +++ b/lib/types/zpool.nix @@ -150,9 +150,9 @@ in topology="" # For shell check mode="${config.mode}" - if [ $mode != "prescribed" ]; then - ${if hasTopology then - ''topology="${config.mode} \"''${zfs_devices}\""'' + if [ "$mode" != "prescribed" ]; then + ${if !hasTopology then + ''topology="${config.mode} ''${zfs_devices[*]}"'' else '' echo "topology cannot be set when mode != 'prescribed', skipping creating zpool ${config.name}" >&2 @@ -174,7 +174,6 @@ in devs=''${line#*=} IFS=' ' read -r -a devices <<< "$devs" all_devices+=("''${devices[@]}") - # shellcheck disable=SC2089 topology+=" ''${mode} ''${devices[*]}" done # all_devices sorted should equal zfs_devices sorted @@ -188,7 +187,6 @@ in fi fi if [ $continue -eq 1 ]; then - # shellcheck disable=SC2090 zpool create -f ${config.name} \ -R ${rootMountPoint} \ ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ diff --git a/tests/zfs-with-vdevs.nix b/tests/zfs-with-vdevs.nix new file mode 100644 index 0000000..5f8c67d --- /dev/null +++ b/tests/zfs-with-vdevs.nix @@ -0,0 +1,24 @@ +{ pkgs ? import { } +, diskoLib ? pkgs.callPackage ../lib { } +}: +diskoLib.testLib.makeDiskoTest { + inherit pkgs; + name = "zfs-with-vdevs"; + disko-config = ../example/zfs-with-vdevs.nix; + extraInstallerConfig.networking.hostId = "8425e349"; + extraSystemConfig = { + networking.hostId = "8425e349"; + }; + extraTestScript = '' + def assert_property(ds, property, expected_value): + out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip() + assert ( + out == expected_value + ), f"Expected {property}={expected_value} on {ds}, got: {out}" + + assert_property("zroot", "compression", "zstd") + assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true") + assert_property("zroot/zfs_fs", "compression", "zstd") + machine.succeed("mountpoint /zfs_fs"); + ''; +}