lib/jsonschema: render defaults for submodule options
this relaxes the constraint that options of type `submodule` are always required, and will render benign default values.
This commit is contained in:
committed by
Valentin Gagarin
parent
15fe06fbf5
commit
af7915a564
@@ -425,7 +425,19 @@ rec {
|
|||||||
# return jsonschema property definition for submodule
|
# return jsonschema property definition for submodule
|
||||||
# then (lib.attrNames (option.type.getSubOptions option.loc).opt)
|
# then (lib.attrNames (option.type.getSubOptions option.loc).opt)
|
||||||
then
|
then
|
||||||
exposedModuleInfo // example // description // parseSubOptions { inherit option; }
|
(lib.recursiveUpdate exposedModuleInfo (
|
||||||
|
if (default ? default) then
|
||||||
|
default
|
||||||
|
else
|
||||||
|
{
|
||||||
|
"$exportedModuleInfo" = {
|
||||||
|
required = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
))
|
||||||
|
// example
|
||||||
|
// description
|
||||||
|
// parseSubOptions { inherit option; }
|
||||||
# throw error if option type is not supported
|
# throw error if option type is not supported
|
||||||
else
|
else
|
||||||
notSupported option;
|
notSupported option;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
default = false;
|
default = false;
|
||||||
description = "Is the user an admin?";
|
description = "Is the user an admin?";
|
||||||
};
|
};
|
||||||
# a submodule option
|
# a submodule option without default
|
||||||
services = lib.mkOption {
|
services = lib.mkOption {
|
||||||
type = lib.types.submodule {
|
type = lib.types.submodule {
|
||||||
options.opt = lib.mkOption {
|
options.opt = lib.mkOption {
|
||||||
@@ -30,6 +30,17 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
# a submodule option with default
|
||||||
|
programs = lib.mkOption {
|
||||||
|
type = lib.types.submodule {
|
||||||
|
options.opt = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "bar";
|
||||||
|
description = "Another submodule option";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
# attrs of int
|
# attrs of int
|
||||||
userIds = lib.mkOption {
|
userIds = lib.mkOption {
|
||||||
type = lib.types.attrsOf lib.types.int;
|
type = lib.types.attrsOf lib.types.int;
|
||||||
|
|||||||
@@ -92,6 +92,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"programs": {
|
||||||
|
"$exportedModuleInfo": { "path": ["programs"] },
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"opt": {
|
||||||
|
"$exportedModuleInfo": { "path": ["programs", "opt"] },
|
||||||
|
"type": "string",
|
||||||
|
"default": "bar",
|
||||||
|
"description": "Another submodule option"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {}
|
||||||
|
},
|
||||||
"destinations": {
|
"destinations": {
|
||||||
"$exportedModuleInfo": { "path": ["destinations"] },
|
"$exportedModuleInfo": { "path": ["destinations"] },
|
||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
|
|||||||
@@ -324,6 +324,7 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
default = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -354,6 +355,7 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
default = { };
|
||||||
required = [ "opt" ];
|
required = [ "opt" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user