From 03e19b4f67f1f28ee5fff660ea7cdb2489b03597 Mon Sep 17 00:00:00 2001 From: Bert Proesmans Date: Tue, 30 Sep 2025 11:24:04 +0000 Subject: [PATCH 1/4] Feature(zfs_volume); Add internal option for fully qualified zfs path --- lib/types/zfs_volume.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/types/zfs_volume.nix b/lib/types/zfs_volume.nix index 631c243..1095415 100644 --- a/lib/types/zfs_volume.nix +++ b/lib/types/zfs_volume.nix @@ -13,6 +13,12 @@ default = config._module.args.name; description = "Name of the dataset"; }; + _name = lib.mkOption { + type = lib.types.str; + default = "${config._parent.name}/${config.name}"; + internal = true; + description = "Fully quantified name for dataset"; + }; type = lib.mkOption { type = lib.types.enum [ "zfs_volume" ]; default = "zfs_volume"; @@ -61,8 +67,8 @@ _create = diskoLib.mkCreateOption { inherit config options; default = '' - if ! zfs get type "${config._parent.name}/${config.name}" >/dev/null 2>&1; then - zfs create "${config._parent.name}/${config.name}" \ + if ! zfs get type "${config._name}" >/dev/null 2>&1; then + zfs create "${config._name}" \ ${ lib.concatStringsSep " " ( lib.mapAttrsToList (n: v: "-o ${n}=${lib.escapeShellArg v}") config.options From 5c7406ecc5dd63816f0d8c30bef0339f8d680390 Mon Sep 17 00:00:00 2001 From: Bert Proesmans Date: Tue, 30 Sep 2025 11:26:51 +0000 Subject: [PATCH 2/4] Fix(zfs_volume); Volume mount/unmount with encryption - Fix consistent use of fully qualified dataset path - Add idempotent unmounting with encryption keys --- lib/types/zfs_volume.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/types/zfs_volume.nix b/lib/types/zfs_volume.nix index 1095415..3f43ffa 100644 --- a/lib/types/zfs_volume.nix +++ b/lib/types/zfs_volume.nix @@ -88,8 +88,8 @@ default = { dev = '' ${lib.optionalString (config.options.keylocation or "none" != "none") '' - if [ "$(zfs get keystatus ${config.name} -H -o value)" == "unavailable" ]; then - zfs load-key ${config.name} + if [ "$(zfs get keystatus ${config._name} -H -o value)" == "unavailable" ]; then + zfs load-key ${config._name} fi ''} @@ -102,9 +102,11 @@ inherit config options; default = { dev = '' - ${lib.optionalString ( - config.options.keylocation or "none" != "none" - ) "zfs unload-key ${config.name}"} + ${lib.optionalString (config.options.keylocation or "none" != "none") '' + if [ "$(zfs get keystatus ${config._name} -H -o value)" == "available" ]; then + zfs unload-key ${config._name} + fi + ''} ${config.content._unmount.dev or ""} ''; From 2c40806b9370ffbbfcf15487cd714173c7ac8811 Mon Sep 17 00:00:00 2001 From: Bert Proesmans Date: Sun, 2 Nov 2025 13:43:02 +0000 Subject: [PATCH 3/4] feat(mdadm); start mdadm before mounting datasets --- lib/types/mdadm.nix | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/types/mdadm.nix b/lib/types/mdadm.nix index 277d9bc..bf28200 100644 --- a/lib/types/mdadm.nix +++ b/lib/types/mdadm.nix @@ -82,8 +82,19 @@ }; _mount = diskoLib.mkMountOption { inherit config options; - default = lib.optionalAttrs (config.content != null) config.content._mount; - # TODO we probably need to assemble the mdadm somehow + default = + let + content = lib.optionalAttrs (config.content != null) config.content._mount; + in + { + fs = content.fs or { }; + dev = '' + if ! test -e "/dev/md/${config.name}"; then + mdadm --assemble --scan + fi + ${content.dev or ""} + ''; + }; }; _unmount = diskoLib.mkUnmountOption { inherit config options; From 8ff2716d01dd00c25abff97da485dca4282e5ff1 Mon Sep 17 00:00:00 2001 From: Bert Proesmans Date: Tue, 30 Sep 2025 11:10:44 +0000 Subject: [PATCH 4/4] Fix(test); Add idempotent unmounting to tests of example configuration --- lib/tests.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tests.nix b/lib/tests.nix index 7d96372..4b8b95a 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -381,6 +381,9 @@ let machine.succeed("${lib.getExe nodes.machine.system.build.format}") machine.succeed("${lib.getExe nodes.machine.system.build.mount}") machine.succeed("${lib.getExe nodes.machine.system.build.mount}") # verify that mount is idempotent + machine.succeed("${lib.getExe nodes.machine.system.build.unmount}") + machine.succeed("${lib.getExe nodes.machine.system.build.unmount}") # verify that unmount is idempotent + machine.succeed("${lib.getExe nodes.machine.system.build.mount}") # verify that mount is idempotent machine.succeed("${lib.getExe nodes.machine.system.build.destroyFormatMount} --yes-wipe-all-disks") # verify that we can destroy and recreate again machine.succeed("mkdir -p /mnt/home") machine.succeed("touch /mnt/home/testfile")