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
15 changes: 13 additions & 2 deletions lib/types/mdadm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,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;
Expand Down
22 changes: 15 additions & 7 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 @@ -92,9 +98,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 ""}
'';
Expand Down