From dfd98a5da26c341cf3b7e6fe7e2dbbaeb0af519c Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 14 Jun 2022 02:12:43 +0200 Subject: [PATCH] lib.deferredModule: Make it properly singular --- lib/tests/modules/deferred-module.nix | 2 +- lib/types.nix | 4 +++- .../development/option-types.section.md | 5 +++-- .../development/option-types.section.xml | 20 +++++++++++-------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/tests/modules/deferred-module.nix b/lib/tests/modules/deferred-module.nix index e963c5a845c1..d03c60b029bf 100644 --- a/lib/tests/modules/deferred-module.nix +++ b/lib/tests/modules/deferred-module.nix @@ -12,7 +12,7 @@ in ({ config, ... }: { _file = "generic.nix"; options.nodes = mkOption { - type = lazyAttrsOf (submodule { imports = config.default; }); + type = lazyAttrsOf (submodule { imports = [ config.default ]; }); default = {}; }; options.default = mkOption { diff --git a/lib/types.nix b/lib/types.nix index 68dfa5843dee..354714b28733 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -549,7 +549,9 @@ rec { name = "deferredModule"; description = "module"; check = x: isAttrs x || isFunction x || path.check x; - merge = loc: defs: staticModules ++ map (def: lib.setDefaultModuleLocation "${def.file}, via option ${showOption loc}" def.value) defs; + merge = loc: defs: { + imports = staticModules ++ map (def: lib.setDefaultModuleLocation "${def.file}, via option ${showOption loc}" def.value) defs; + }; inherit (submoduleWith { modules = staticModules; }) getSubOptions getSubModules; diff --git a/nixos/doc/manual/development/option-types.section.md b/nixos/doc/manual/development/option-types.section.md index 0241aae1dc89..e4e6cfec957f 100644 --- a/nixos/doc/manual/development/option-types.section.md +++ b/nixos/doc/manual/development/option-types.section.md @@ -227,8 +227,9 @@ Value types are types that take a value parameter. It can be set multiple times. - Module authors can use its value, which is always a list of module values, - in `imports` or in `submoduleWith`'s `modules` parameter. + Module authors can use its value in `imports`, in `submoduleWith`'s `modules` + or in `evalModules`' `modules` parameter, among other places. + Note that `imports` must be evaluated before the module fixpoint. Because of this, deferred modules can only be imported into "other" fixpoints, such as submodules. diff --git a/nixos/doc/manual/from_md/development/option-types.section.xml b/nixos/doc/manual/from_md/development/option-types.section.xml index 820646be671f..e3d161e4d351 100644 --- a/nixos/doc/manual/from_md/development/option-types.section.xml +++ b/nixos/doc/manual/from_md/development/option-types.section.xml @@ -441,14 +441,18 @@ It can be set multiple times. - Module authors can use its value, which is always a list of - module values, in imports or in - submoduleWith’s - modules parameter. Note that - imports must be evaluated before the - module fixpoint. Because of this, deferred modules can only - be imported into other fixpoints, such as - submodules. + Module authors can use its value in + imports, in + submoduleWiths + modules or in + evalModules + modules parameter, among other places. + + + Note that imports must be evaluated + before the module fixpoint. Because of this, deferred + modules can only be imported into other + fixpoints, such as submodules. One use case for this type is the type of a