mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-12 16:10:03 +01:00
types: refactor into diskoLib
This commit is contained in:
parent
efb2016c8e
commit
22b33a4fd6
21 changed files with 146 additions and 146 deletions
|
|
@ -1,86 +0,0 @@
|
|||
{ config, options, lib, diskoLib, optionTypes, rootMountPoint, ... }:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = config._module.args.name;
|
||||
description = "Name of the dataset";
|
||||
};
|
||||
type = lib.mkOption {
|
||||
type = lib.types.enum [ "zfs_fs" ];
|
||||
default = "zfs_fs";
|
||||
internal = true;
|
||||
description = "Type";
|
||||
};
|
||||
options = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.str;
|
||||
default = { };
|
||||
description = "Options to set for the dataset";
|
||||
};
|
||||
mountOptions = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ "defaults" ];
|
||||
description = "Mount options";
|
||||
};
|
||||
|
||||
mountpoint = lib.mkOption {
|
||||
type = lib.types.nullOr optionTypes.absolute-pathname;
|
||||
default = null;
|
||||
description = "Path to mount the dataset to";
|
||||
};
|
||||
|
||||
_meta = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo diskoLib.jsonType;
|
||||
default = dev: { };
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
inherit config options;
|
||||
# -u prevents mounting newly created datasets, which is
|
||||
# important to prevent accidental shadowing of mount points
|
||||
# since (create order != mount order)
|
||||
default = { zpool }: ''
|
||||
zfs create -u ${zpool}/${config.name} \
|
||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)}
|
||||
'';
|
||||
};
|
||||
_mount = diskoLib.mkMountOption {
|
||||
inherit config options;
|
||||
default = { zpool }:
|
||||
lib.optionalAttrs (config.options.mountpoint or "" != "none") {
|
||||
fs.${config.mountpoint} = ''
|
||||
if ! findmnt ${zpool}/${config.name} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
|
||||
mount ${zpool}/${config.name} "${rootMountPoint}${config.mountpoint}" \
|
||||
-o X-mount.mkdir \
|
||||
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
|
||||
${lib.optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \
|
||||
-t zfs
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = zpool:
|
||||
lib.optional (config.options.mountpoint or "" != "none") {
|
||||
fileSystems.${config.mountpoint} = {
|
||||
device = "${zpool}/${config.name}";
|
||||
fsType = "zfs";
|
||||
options = config.mountOptions ++ lib.optional ((config.options.mountpoint or "") != "legacy") "zfsutil";
|
||||
};
|
||||
};
|
||||
description = "NixOS configuration";
|
||||
};
|
||||
_pkgs = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs: [ pkgs.util-linux ];
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue