2023-06-07 14:42:39 +03:00
|
|
|
{ config, options, lib, diskoLib, rootMountPoint, parent, ... }:
|
2023-01-28 18:19:13 +03:00
|
|
|
{
|
|
|
|
options = {
|
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = config._module.args.name;
|
|
|
|
description = "Name of the dataset";
|
|
|
|
};
|
2023-12-30 03:25:06 +03:00
|
|
|
|
|
|
|
_name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "${config._parent.name}/${config.name}";
|
|
|
|
internal = true;
|
|
|
|
description = "Fully quantified name for dataset";
|
|
|
|
};
|
|
|
|
|
2023-01-28 18:19:13 +03:00
|
|
|
type = lib.mkOption {
|
2023-04-07 19:29:48 +03:00
|
|
|
type = lib.types.enum [ "zfs_fs" ];
|
|
|
|
default = "zfs_fs";
|
2023-01-28 18:19:13 +03:00
|
|
|
internal = true;
|
|
|
|
description = "Type";
|
|
|
|
};
|
2023-12-30 03:25:06 +03:00
|
|
|
|
2023-01-28 18:19:13 +03:00
|
|
|
options = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf lib.types.str;
|
|
|
|
default = { };
|
|
|
|
description = "Options to set for the dataset";
|
|
|
|
};
|
2023-12-30 03:25:06 +03:00
|
|
|
|
2023-01-28 18:19:13 +03:00
|
|
|
mountOptions = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ "defaults" ];
|
|
|
|
description = "Mount options";
|
|
|
|
};
|
|
|
|
|
|
|
|
mountpoint = lib.mkOption {
|
2023-05-16 14:40:03 +03:00
|
|
|
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
2023-01-28 18:19:13 +03:00
|
|
|
default = null;
|
|
|
|
description = "Path to mount the dataset to";
|
|
|
|
};
|
|
|
|
|
2023-06-07 14:42:39 +03:00
|
|
|
_parent = lib.mkOption {
|
|
|
|
internal = true;
|
|
|
|
default = parent;
|
|
|
|
};
|
2023-12-30 03:25:06 +03:00
|
|
|
|
2023-01-28 18:19:13 +03:00
|
|
|
_meta = lib.mkOption {
|
|
|
|
internal = true;
|
|
|
|
readOnly = true;
|
|
|
|
type = lib.types.functionTo diskoLib.jsonType;
|
2023-06-06 14:32:47 +03:00
|
|
|
default = _dev: { };
|
2023-01-28 18:19:13 +03:00
|
|
|
description = "Metadata";
|
|
|
|
};
|
2023-12-30 03:25:06 +03:00
|
|
|
|
2023-01-28 18:19:13 +03:00
|
|
|
_create = diskoLib.mkCreateOption {
|
|
|
|
inherit config options;
|
2023-04-29 20:42:44 +03:00
|
|
|
# -u prevents mounting newly created datasets, which is
|
|
|
|
# important to prevent accidental shadowing of mount points
|
|
|
|
# since (create order != mount order)
|
2023-06-15 22:48:52 +03:00
|
|
|
# -p creates parents automatically
|
2023-07-01 20:02:01 +03:00
|
|
|
default = ''
|
2023-12-30 03:25:06 +03:00
|
|
|
zfs create -up ${config._name} \
|
2023-04-07 19:29:48 +03:00
|
|
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)}
|
2023-01-28 18:19:13 +03:00
|
|
|
'';
|
2023-12-30 03:25:06 +03:00
|
|
|
} // { readOnly = false; };
|
|
|
|
|
2023-01-28 18:19:13 +03:00
|
|
|
_mount = diskoLib.mkMountOption {
|
|
|
|
inherit config options;
|
2023-07-01 20:02:01 +03:00
|
|
|
default =
|
2023-12-30 03:25:06 +03:00
|
|
|
lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
2023-01-28 18:19:13 +03:00
|
|
|
fs.${config.mountpoint} = ''
|
2023-12-30 03:25:06 +03:00
|
|
|
if ! findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
|
|
|
mount ${config._name} "${rootMountPoint}${config.mountpoint}" \
|
2023-07-02 01:17:48 +03:00
|
|
|
-o X-mount.mkdir \
|
|
|
|
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
|
|
|
|
${lib.optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \
|
|
|
|
-t zfs
|
2023-01-28 18:19:13 +03:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2023-12-30 03:25:06 +03:00
|
|
|
|
2023-01-28 18:19:13 +03:00
|
|
|
_config = lib.mkOption {
|
|
|
|
internal = true;
|
|
|
|
readOnly = true;
|
2023-07-01 20:02:01 +03:00
|
|
|
default =
|
2023-12-30 03:25:06 +03:00
|
|
|
lib.optional (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
2023-01-28 18:19:13 +03:00
|
|
|
fileSystems.${config.mountpoint} = {
|
2023-12-30 03:25:06 +03:00
|
|
|
device = "${config._name}";
|
2023-01-28 18:19:13 +03:00
|
|
|
fsType = "zfs";
|
|
|
|
options = config.mountOptions ++ lib.optional ((config.options.mountpoint or "") != "legacy") "zfsutil";
|
|
|
|
};
|
2023-04-07 19:29:48 +03:00
|
|
|
};
|
2023-01-28 18:19:13 +03:00
|
|
|
description = "NixOS configuration";
|
|
|
|
};
|
2023-12-30 03:25:06 +03:00
|
|
|
|
2023-01-28 18:19:13 +03:00
|
|
|
_pkgs = lib.mkOption {
|
|
|
|
internal = true;
|
|
|
|
readOnly = true;
|
|
|
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
2023-04-07 19:29:48 +03:00
|
|
|
default = pkgs: [ pkgs.util-linux ];
|
2023-01-28 18:19:13 +03:00
|
|
|
description = "Packages";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2023-04-07 19:29:48 +03:00
|
|
|
|