Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion lib/types/zfs_fs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 15 additions & 5 deletions lib/types/zfs_volume.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -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
''}

Expand All @@ -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 ""}
'';
Expand Down