diff --git a/lib/tests.nix b/lib/tests.nix index d0cba72e..e5d64aab 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -345,6 +345,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") diff --git a/lib/types/zfs_fs.nix b/lib/types/zfs_fs.nix index 129ddf58..37e1c6fe 100644 --- a/lib/types/zfs_fs.nix +++ b/lib/types/zfs_fs.nix @@ -143,7 +143,11 @@ inherit config options; default = (lib.optionalAttrs (config.options.keylocation or "none" != "none") { - dev = "zfs unload-key ${config.name}"; + dev = '' + if [ "$(zfs get keystatus ${config._name} -H -o value)" == "available" ]; then + zfs unload-key ${config._name} + fi + ''; }) // lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") diff --git a/lib/types/zfs_volume.nix b/lib/types/zfs_volume.nix index 8f2b60a4..3b079a7c 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}=${v}") config.options)} \ -V ${config.size} ${toString (builtins.map lib.escapeShellArg config.extraArgs)} zvol_wait @@ -78,8 +84,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 ''} @@ -94,7 +100,11 @@ dev = '' ${lib.optionalString ( config.options.keylocation or "none" != "none" - ) "zfs unload-key ${config.name}"} + ) '' + if [ "$(zfs get keystatus ${config._name} -H -o value)" == "available" ]; then + zfs unload-key ${config._name} + fi + ''} ${config.content._unmount.dev or ""} '';