mirror of
https://github.com/nix-community/disko.git
synced 2024-09-19 18:47:16 +03:00
types: pass parent node to all subTypes
This commit is contained in:
parent
e0179917d8
commit
62f939e213
@ -7,31 +7,40 @@ let
|
|||||||
diskoLib = {
|
diskoLib = {
|
||||||
# like lib.types.oneOf but instead of a list takes an attrset
|
# like lib.types.oneOf but instead of a list takes an attrset
|
||||||
# uses the field "type" to find the correct type in the attrset
|
# uses the field "type" to find the correct type in the attrset
|
||||||
subType = typeAttr: lib.mkOptionType rec {
|
subType = { types, extraArgs ? { parent = { type = "rootNode"; name = "root"; }; } }: lib.mkOptionType rec {
|
||||||
name = "subType";
|
name = "subType";
|
||||||
description = "one of ${concatStringsSep "," (attrNames typeAttr)}";
|
description = "one of ${concatStringsSep "," (attrNames types)}";
|
||||||
check = x: if x ? type then typeAttr.${x.type}.check x else throw "No type option set in:\n${generators.toPretty {} x}";
|
check = x: if x ? type then types.${x.type}.check x else throw "No type option set in:\n${generators.toPretty {} x}";
|
||||||
merge = loc: foldl' (_res: def: typeAttr.${def.value.type}.merge loc [ def ]) { };
|
merge = loc: foldl' (res: def: types.${def.value.type}.merge loc [
|
||||||
nestedTypes = typeAttr;
|
# we add a dummy root parent node to render documentation
|
||||||
|
(lib.recursiveUpdate { value._module.args = extraArgs; } def)
|
||||||
|
]) { };
|
||||||
|
nestedTypes = types;
|
||||||
};
|
};
|
||||||
|
|
||||||
# option for valid contents of partitions (basically like devices, but without tables)
|
# option for valid contents of partitions (basically like devices, but without tables)
|
||||||
partitionType = lib.mkOption {
|
partitionType = extraArgs: lib.mkOption {
|
||||||
type = lib.types.nullOr (diskoLib.subType { inherit (diskoLib.types) btrfs filesystem zfs mdraid luks lvm_pv swap; });
|
type = lib.types.nullOr (diskoLib.subType {
|
||||||
|
types = { inherit (diskoLib.types) btrfs filesystem zfs mdraid luks lvm_pv swap; };
|
||||||
|
inherit extraArgs;
|
||||||
|
});
|
||||||
default = null;
|
default = null;
|
||||||
description = "The type of partition";
|
description = "The type of partition";
|
||||||
};
|
};
|
||||||
|
|
||||||
# option for valid contents of devices
|
# option for valid contents of devices
|
||||||
deviceType = lib.mkOption {
|
deviceType = extraArgs: lib.mkOption {
|
||||||
type = lib.types.nullOr (diskoLib.subType { inherit (diskoLib.types) table btrfs filesystem zfs mdraid luks lvm_pv swap; });
|
type = lib.types.nullOr (diskoLib.subType {
|
||||||
|
types = { inherit (diskoLib.types) table table_gpt btrfs filesystem zfs mdraid luks lvm_pv swap; };
|
||||||
|
inherit extraArgs;
|
||||||
|
});
|
||||||
default = null;
|
default = null;
|
||||||
description = "The type of device";
|
description = "The type of device";
|
||||||
};
|
};
|
||||||
|
|
||||||
/* deepMergeMap takes a function and a list of attrsets and deep merges them
|
/* deepMergeMap takes a function and a list of attrsets and deep merges them
|
||||||
|
|
||||||
deepMergeMap :: -> (AttrSet -> AttrSet ) -> [ AttrSet ] -> Attrset
|
deepMergeMap :: (AttrSet -> AttrSet ) -> [ AttrSet ] -> Attrset
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
deepMergeMap (x: x.t = "test") [ { x = { y = 1; z = 3; }; } { x = { bla = 234; }; } ]
|
deepMergeMap (x: x.t = "test") [ { x = { y = 1; z = 3; }; } { x = { bla = 234; }; } ]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ config, options, diskoLib, lib, rootMountPoint, ... }:
|
{ config, options, diskoLib, lib, rootMountPoint, parent, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
@ -55,6 +55,10 @@
|
|||||||
default = null;
|
default = null;
|
||||||
description = "A path to mount the BTRFS filesystem to.";
|
description = "A path to mount the BTRFS filesystem to.";
|
||||||
};
|
};
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
type = diskoLib.optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile
|
type = diskoLib.optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile
|
||||||
description = "Device path";
|
description = "Device path";
|
||||||
};
|
};
|
||||||
content = diskoLib.deviceType;
|
content = diskoLib.deviceType { parent = config; };
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ config, options, lib, diskoLib, rootMountPoint, ... }:
|
{ config, options, lib, diskoLib, rootMountPoint, parent, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
@ -25,6 +25,10 @@
|
|||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
description = "Format of the filesystem";
|
description = "Format of the filesystem";
|
||||||
};
|
};
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ config, options, lib, diskoLib, ... }:
|
{ config, options, lib, diskoLib, parent, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
@ -33,7 +33,11 @@
|
|||||||
description = "Extra arguments to pass to `cryptsetup luksOpen` when opening";
|
description = "Extra arguments to pass to `cryptsetup luksOpen` when opening";
|
||||||
example = [ "--allow-discards" ];
|
example = [ "--allow-discards" ];
|
||||||
};
|
};
|
||||||
content = diskoLib.deviceType;
|
content = diskoLib.deviceType { parent = config; };
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ config, options, lib, diskoLib, ... }:
|
{ config, options, lib, diskoLib, parent, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
@ -10,6 +10,10 @@
|
|||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
description = "Volume group";
|
description = "Volume group";
|
||||||
};
|
};
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
default = [ ];
|
default = [ ];
|
||||||
description = "Extra arguments";
|
description = "Extra arguments";
|
||||||
};
|
};
|
||||||
content = diskoLib.partitionType;
|
content = diskoLib.partitionType { parent = config; };
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
default = { };
|
default = { };
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
default = "default";
|
default = "default";
|
||||||
description = "Metadata";
|
description = "Metadata";
|
||||||
};
|
};
|
||||||
content = diskoLib.deviceType;
|
content = diskoLib.deviceType { parent = config; };
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ config, options, lib, diskoLib, ... }:
|
{ config, options, lib, diskoLib, parent, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
@ -11,6 +11,10 @@
|
|||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
description = "Name";
|
description = "Name";
|
||||||
};
|
};
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ diskoLib, config, options, lib, ... }:
|
{ diskoLib, config, options, lib, parent, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
@ -11,6 +11,10 @@
|
|||||||
default = false;
|
default = false;
|
||||||
description = "Whether to randomly encrypt the swap";
|
description = "Whether to randomly encrypt the swap";
|
||||||
};
|
};
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ config, options, lib, diskoLib, ... }:
|
{ config, options, lib, diskoLib, parent, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
@ -48,12 +48,16 @@
|
|||||||
default = false;
|
default = false;
|
||||||
description = "Whether to make the partition bootable";
|
description = "Whether to make the partition bootable";
|
||||||
};
|
};
|
||||||
content = diskoLib.partitionType;
|
content = diskoLib.partitionType { parent = config; };
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
default = [ ];
|
default = [ ];
|
||||||
description = "List of partitions to add to the partition table";
|
description = "List of partitions to add to the partition table";
|
||||||
};
|
};
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ config, options, lib, diskoLib, ... }:
|
{ config, options, lib, diskoLib, parent, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
@ -10,6 +10,10 @@
|
|||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
description = "Name of the ZFS pool";
|
description = "Name of the ZFS pool";
|
||||||
};
|
};
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ config, options, lib, diskoLib, rootMountPoint, ... }:
|
{ config, options, lib, diskoLib, rootMountPoint, parent, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
@ -29,6 +29,10 @@
|
|||||||
description = "Path to mount the dataset to";
|
description = "Path to mount the dataset to";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ config, options, lib, diskoLib, ... }:
|
{ config, options, lib, diskoLib, parent, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
@ -30,8 +30,12 @@
|
|||||||
description = "Size of the dataset";
|
description = "Size of the dataset";
|
||||||
};
|
};
|
||||||
|
|
||||||
content = diskoLib.partitionType;
|
content = diskoLib.partitionType { parent = config; };
|
||||||
|
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -49,7 +49,10 @@
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
datasets = lib.mkOption {
|
datasets = lib.mkOption {
|
||||||
type = lib.types.attrsOf (diskoLib.subType { inherit (diskoLib.types) zfs_fs zfs_volume; });
|
type = lib.types.attrsOf (diskoLib.subType {
|
||||||
|
types = { inherit (diskoLib.types) zfs_fs zfs_volume; };
|
||||||
|
extraArgs.parent = config;
|
||||||
|
});
|
||||||
description = "List of datasets to define";
|
description = "List of datasets to define";
|
||||||
};
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
|
Loading…
Reference in New Issue
Block a user