summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJörg Thalheim <joerg@thalheim.io>2022-08-26 10:28:07 +0200
committerJörg Thalheim <joerg@thalheim.io>2022-08-26 10:29:49 +0200
commit722dde361ca51864fd9b3b6b9a78875e436fbc24 (patch)
tree31b5d48e3b1601b074e503bdc25f20ad62edb596
parent57b7c5506a64e169370f291bffa75d2888027ee9 (diff)
zfs: support for root dataset mountpoint and mountpoint=none
-rw-r--r--default.nix35
-rw-r--r--example/zfs.nix7
-rw-r--r--tests/zfs.nix4
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";
@@ -25,6 +27,11 @@
}
{
type = "zfs_filesystem";
+ name = "zfs_unmounted_fs";
+ options.mountpoint = "none";
+ }
+ {
+ type = "zfs_filesystem";
name = "zfs_legacy_fs";
options.mountpoint = "legacy";
mountpoint = "/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");