From 722dde361ca51864fd9b3b6b9a78875e436fbc24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 26 Aug 2022 10:28:07 +0200 Subject: zfs: support for root dataset mountpoint and mountpoint=none --- default.nix | 35 +++++++++++++++++++++++++++-------- example/zfs.nix | 7 +++++++ tests/zfs.nix | 4 ++-- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/default.nix b/default.nix index ac84345..1865d69 100644 --- a/default.nix +++ b/default.nix @@ -256,29 +256,48 @@ let mount.zfs = mount.noop; - mount.zpool = q: x: ( + mount.zpool = q: x: + let + datasets = [{ + inherit (q) name; + type = "zfs_filesystem"; + dataset = q.name; + mountpoint = x.mountpoint or "/${q.name}"; + options = q.rootFsOptions or { }; + }] ++ x.datasets; + in recursiveUpdate - (foldl' recursiveUpdate { } (map (mount-f (q // { pool = q.name; })) x.datasets)) + (foldl' recursiveUpdate { } + ( + (map + (x: mount-f + ({ + dataset = x.dataset or "${q.name}/${x.name}"; + mountpoint = x.mountpoint or "/${q.name}/${x.name}"; + } // q) + x) + datasets) + ) + ) { zpool.${q.device} = '' zpool list '${q.name}' >/dev/null 2>/dev/null || zpool import '${q.name}' ''; - } - ); + }; mount.zfs_filesystem = q: x: { - zfs.${x.mountpoint} = '' - if ! findmnt '${q.pool}/${x.name}' /mnt${x.mountpoint} > /dev/null 2>&1; then + 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.pool}/${x.name} /mnt${x.mountpoint} \ + -t zfs ${q.dataset} /mnt${q.mountpoint} \ -o X-mount.mkdir fi ''; }; mount.zfs_volume = q: x: - mount-f { device = "/dev/zvol/${q.pool}/${x.name}"; } x.content; + mount-f { device = "/dev/zvol/${q.dataset}"; } x.content; in { diff --git a/example/zfs.nix b/example/zfs.nix index 2b56bd7..60e4700 100644 --- a/example/zfs.nix +++ b/example/zfs.nix @@ -16,6 +16,8 @@ compression = "lz4"; "com.sun:auto-snapshot" = "false"; }; + mountpoint = "/"; + datasets = [ { type = "zfs_filesystem"; @@ -23,6 +25,11 @@ mountpoint = "/zfs_fs"; options."com.sun:auto-snapshot" = "true"; } + { + type = "zfs_filesystem"; + name = "zfs_unmounted_fs"; + options.mountpoint = "none"; + } { type = "zfs_filesystem"; name = "zfs_legacy_fs"; diff --git a/tests/zfs.nix b/tests/zfs.nix index ebc6b04..5940c4d 100644 --- a/tests/zfs.nix +++ b/tests/zfs.nix @@ -17,9 +17,9 @@ makeDiskoTest { assert_property("zroot", "com.sun:auto-snapshot", "false") assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true") assert_property("zroot/zfs_testvolume", "volsize", "10M") + assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none") - # FIXME: we cannot mount rootfs yet - #machine.succeed("mountpoint /mnt"); + machine.succeed("mountpoint /mnt"); machine.succeed("mountpoint /mnt/zfs_fs"); machine.succeed("mountpoint /mnt/zfs_legacy_fs"); machine.succeed("mountpoint /mnt/ext4onzfs"); -- cgit v1.2.3