From 4ac09ea80a2b33d3fe68e59fa0bede9e33929cb4 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Sat, 14 Dec 2019 00:15:23 +0100 Subject: [PATCH 1/2] nixos/docs: Add docs for types.fullSubmodule --- nixos/doc/manual/development/option-types.xml | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/nixos/doc/manual/development/option-types.xml b/nixos/doc/manual/development/option-types.xml index 8fcbb627342b2..8ab7ea91ab76b 100644 --- a/nixos/doc/manual/development/option-types.xml +++ b/nixos/doc/manual/development/option-types.xml @@ -259,12 +259,39 @@ A set of sub options o. o can be an attribute set or a function returning an attribute set. Submodules are used in composed types to - create modular options. Submodule are detailed in + create modular options. This is equivalent to types.fullSubmodule { configDefault = true; modules = toList o; }. Submodules are detailed in . + + + types.fullSubmodule { modules ? [], specialArgs ? {}, configDefault ? false } + + + + Like types.submodule, but more flexible and without as much magic. It has arguments + + + modules + A list of modules to use by default for this submodule type. This gets combined with all option definitions to build the final list of modules that will be included. + + + specialArgs + An attribute set of extra arguments that get passed to the module functions. For most arguments, the option _module.args should be used instead, since it allows overriding. specialArgs should only be used for arguments that can't go through the module fixed-point, because of infinite recursion or other problems. A good use-case example is overriding the lib argument that gets passed to all modules, because lib itself is used to define _module.args, which makes using _module.args impossible. + + + configDefault + Whether definitions of this type should default to the config section of a module (see ) if it is an attribute set. Enabling this only has a benefit when the submodule defines an option named config or options. In such a case it would allow the option to be set with the-submodule.config = "value" instead of requiring the-submodule.config.config = "value". This is because only when modules don't set the config or options keys, all keys are interpreted as option definitions in the config section. Enabling this option explicitly puts all definitions in the config section. + + + This option defaults to false because enabling it makes declaring non-config module sections difficult. + + + + + From 571c7daa6c4c3c32c6ed0ef5b9b2393edb06383e Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Sun, 15 Dec 2019 21:02:30 +0100 Subject: [PATCH 2/2] lib/types: Allow fullSubmodule to hide sub options This is needed for allowing the container.* option to be rewritten with fullSubmodule such that not all NixOS options are doubly exposed in the options listing --- lib/types.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/types.nix b/lib/types.nix index ee6163229fd60..acad53d7f5cac 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -367,6 +367,7 @@ rec { { configDefault ? false , modules ? [] , specialArgs ? {} + , hideSubOptions ? false }@attrs: let inherit (lib.modules) evalModules; @@ -390,7 +391,7 @@ rec { args.name = last loc; prefix = loc; }).config; - getSubOptions = prefix: (evalModules + getSubOptions = prefix: optionalAttrs (!hideSubOptions) (evalModules { inherit modules prefix specialArgs; # This is a work-around due to the fact that some sub-modules, # such as the one included in an attribute set, expects a "args"