diff options
-rw-r--r-- | default.nix | 24 | ||||
-rw-r--r-- | example/zfs-over-legacy.nix | 42 | ||||
-rw-r--r-- | tests/zfs-over-legacy.nix | 12 |
3 files changed, 65 insertions, 13 deletions
diff --git a/default.nix b/default.nix index 1865d69..51b70f5 100644 --- a/default.nix +++ b/default.nix @@ -179,7 +179,7 @@ let create.zpool = q: x: '' zpool create ${q.name} \ - ${lib.optionalString (!isNull x.mode || x.mode != "stripe") x.mode} \ + ${lib.optionalString (!isNull (x.mode or null) && x.mode != "stripe") x.mode} \ ${lib.optionalString (isAttrs x.options or null) (concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") x.options))} \ ${lib.optionalString (isAttrs x.rootFsOptions or null) (concatStringsSep " " (mapAttrsToList (n: v: "-O ${n}=${v}") x.rootFsOptions))} \ ''${ZFSDEVICES_${q.name}} @@ -192,11 +192,20 @@ let mount.filesystem = q: x: { fs.${x.mountpoint} = '' if ! findmnt ${q.device} "/mnt${x.mountpoint}" > /dev/null 2>&1; then - mount ${q.device} "/mnt${x.mountpoint}" -o X-mount.mkdir + mount ${q.device} "/mnt${x.mountpoint}" \ + -o X-mount.mkdir \ + ${lib.optionalString (isList x.mountOptions or null) (concatStringsSep " " x.mountOptions)} fi ''; }; + mount.zfs_filesystem = q: x: + optionalAttrs ((x.options.mountpoint or "") != "none") + (mount.filesystem (q // { device = q.dataset; }) (x // { mountOptions = [ + (lib.optionalString ((x.options.mountpoint or "") != "legacy") "-o zfsutil") + "-t zfs" + ]; })); + mount.btrfs = mount.filesystem; mount.devices = q: x: @@ -285,17 +294,6 @@ let ''; }; - mount.zfs_filesystem = q: x: { - zfs.${q.mountpoint} = lib.optionalString ((x.options.mountpoint or "") != "none") '' - if ! findmnt '${q.dataset}' /mnt${q.mountpoint} > /dev/null 2>&1; then - mount \ - ${lib.optionalString ((x.options.mountpoint or "") != "legacy") "-o zfsutil"} \ - -t zfs ${q.dataset} /mnt${q.mountpoint} \ - -o X-mount.mkdir - fi - ''; - }; - mount.zfs_volume = q: x: mount-f { device = "/dev/zvol/${q.dataset}"; } x.content; diff --git a/example/zfs-over-legacy.nix b/example/zfs-over-legacy.nix new file mode 100644 index 0000000..8f5a8bc --- /dev/null +++ b/example/zfs-over-legacy.nix @@ -0,0 +1,42 @@ +{ + type = "devices"; + content = { + vdb = { + type = "table"; + format = "gpt"; + partitions = [ + { + type = "partition"; + # leave space for the grub aka BIOS boot + start = "0%"; + end = "100%"; + part-type = "primary"; + bootable = true; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + } + ]; + }; + vdc = { + type = "zfs"; + pool = "zroot"; + }; + zroot = { + type = "zpool"; + mountpoint = "/"; + + datasets = [ + { + type = "zfs_filesystem"; + name = "zfs_fs"; + mountpoint = "/zfs_fs"; + options."com.sun:auto-snapshot" = "true"; + } + ]; + }; + }; +} + diff --git a/tests/zfs-over-legacy.nix b/tests/zfs-over-legacy.nix new file mode 100644 index 0000000..13f86a9 --- /dev/null +++ b/tests/zfs-over-legacy.nix @@ -0,0 +1,12 @@ +{ pkgs ? (import <nixpkgs> { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = import ../example/zfs-over-legacy.nix; + extraTestScript = '' + machine.succeed("test -e /mnt/zfs_fs"); + machine.succeed("mountpoint /mnt"); + machine.succeed("mountpoint /mnt/zfs_fs"); + ''; +} + |