summaryrefslogtreecommitdiffstats
path: root/lib/types.nix
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2022-05-19 15:15:08 +0200
committerNaïm Favier <n@monade.li>2022-05-19 17:06:39 +0200
commitceebdcfc2ca2d37872c46f224503a36f4d25daa9 (patch)
tree86e5b357d83168237ee5c3d9e46310ec27a2e133 /lib/types.nix
parentddfb78791c95019d3d102d9dcb2631112ca7661f (diff)
lib/types: allow custom `submoduleWith` descriptions
Currently the only way to set the description for a submodule type is to use `freeformType`. This is not ideal as it requires setting a freeform type, and evaluates the submodule config unnecessarily. Instead, add a `description` argument to `submoduleWith`.
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix23
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/types.nix b/lib/types.nix
index 91b040d24553..f53bb132ff5e 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -568,6 +568,7 @@ rec {
{ modules
, specialArgs ? {}
, shorthandOnlyDefinesConfig ? false
+ , description ? null
# Internal variable to avoid `_key` collisions regardless
# of `extendModules`. Wired through by `evalModules`.
@@ -616,10 +617,14 @@ rec {
freeformType = base._module.freeformType;
- in
- mkOptionType rec {
name = "submodule";
- description = freeformType.description or name;
+
+ in
+ mkOptionType {
+ inherit name;
+ description =
+ if description != null then description
+ else freeformType.description or name;
check = x: isAttrs x || isFunction x || path.check x;
merge = loc: defs:
(base.extendModules {
@@ -645,9 +650,7 @@ rec {
functor = defaultFunctor name // {
type = types.submoduleWith;
payload = {
- modules = modules;
- specialArgs = specialArgs;
- shorthandOnlyDefinesConfig = shorthandOnlyDefinesConfig;
+ inherit modules specialArgs shorthandOnlyDefinesConfig description;
};
binOp = lhs: rhs: {
modules = lhs.modules ++ rhs.modules;
@@ -664,6 +667,14 @@ rec {
else if lhs.shorthandOnlyDefinesConfig == rhs.shorthandOnlyDefinesConfig
then lhs.shorthandOnlyDefinesConfig
else throw "A submoduleWith option is declared multiple times with conflicting shorthandOnlyDefinesConfig values";
+ description =
+ if lhs.description == null
+ then rhs.description
+ else if rhs.description == null
+ then lhs.description
+ else if lhs.description == rhs.description
+ then lhs.description
+ else throw "A submoduleWith option is declared multiple times with conflicting descriptions";
};
};
};