Skip to content
Open
3 changes: 3 additions & 0 deletions lib/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,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
1 change: 1 addition & 0 deletions lib/types/luks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ in
cryptsetup close "${config.name}"
fi
'';
fs = lib.optionalAttrs (config.content != null) contentUnmount.fs or { };
};
};
_config = lib.mkOption {
Expand Down
17 changes: 14 additions & 3 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 All @@ -85,7 +96,7 @@
content = lib.optionalAttrs (config.content != null) config.content._unmount;
in
{
fs = content.fs;
fs = content.fs or { };
dev = ''
${content.dev or ""}
if [ -e "/dev/md/${config.name}" ]; then
Expand Down
14 changes: 14 additions & 0 deletions lib/types/nodev.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
rootMountPoint,
...
}:
let
# REF; nixos/modules/tasks/filesystems.nix
specialFSTypes = [
"proc"
"sysfs"
"tmpfs"
"ramfs"
"devtmpfs"
"devpts"
];
in
{
options = {
type = lib.mkOption {
Expand Down Expand Up @@ -86,4 +97,7 @@
description = "Packages";
};
};
config = {
device = lib.mkIf (lib.elem config.fsType specialFSTypes) (lib.mkDefault config.fsType);
};
}
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
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
12 changes: 12 additions & 0 deletions lib/types/zpool.nix
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ in
if [ $continue -eq 1 ]; then
zpool create -f "${config.name}" \
-R ${rootMountPoint} \
${
if
(
# NOTE; It might be necessary to validate the value of config.options.mountpoint too
config.rootFsOptions.canmount or "" == "off"
)
then
# Mountpoint of root(pool)-dataset could be non-empty and ZFS by default prevents shadowing mounts.
"-m none"
else
""
} \
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \
''${topology:+ $topology}
Expand Down