From 426ab31fdeb828886c22ec0e561eca2b90b84b94 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 22 Nov 2021 14:39:44 +0100 Subject: [PATCH 1/2] modules: Document that extendModules is also a module argument --- lib/modules.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/modules.nix b/lib/modules.nix index 92ddc8c5bc70..b381487f68e3 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -74,6 +74,8 @@ rec { override existing configuration fundamentally requires a new fixpoint to be constructed. + This is also available as a module argument. + ‘_module’: A portion of the configuration tree which is elided from ‘config’. It contains some values that are mostly internal to the module system implementation. From d464ccfdd9e101d4f5a112ab58d91ccbb912524a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 22 Nov 2021 14:39:10 +0100 Subject: [PATCH 2/2] modules: Add moduleType to module arguments --- lib/modules.nix | 3 +++ lib/tests/modules.sh | 5 +++++ lib/tests/modules/declare-variants.nix | 9 +++++++++ lib/tests/modules/define-variant.nix | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 lib/tests/modules/declare-variants.nix create mode 100644 lib/tests/modules/define-variant.nix diff --git a/lib/modules.nix b/lib/modules.nix index b381487f68e3..2468b6fbdd22 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -62,6 +62,8 @@ rec { ‘type’: A module system type representing the module set as a submodule, to be extended by configuration from the containing module set. + This is also available as the module argument ‘moduleType’. + ‘extendModules’: A function similar to ‘evalModules’ but building on top of the module set. Its arguments, ‘modules’ and ‘specialArgs’ are added to the existing values. @@ -148,6 +150,7 @@ rec { config = { _module.args = { inherit extendModules; + moduleType = type; } // args; }; }; diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index aba3f08122f5..2f36d6107ca4 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -281,6 +281,11 @@ checkConfigError 'A definition for option .fun.\[function body\]. is not of type checkConfigOutput "b a" config.result ./functionTo/list-order.nix checkConfigOutput "a c" config.result ./functionTo/merging-attrs.nix +# moduleType +checkConfigOutput "a b" config.resultFoo ./declare-variants.nix ./define-variant.nix +checkConfigOutput "a y z" config.resultFooBar ./declare-variants.nix ./define-variant.nix +checkConfigOutput "a b c" config.resultFooFoo ./declare-variants.nix ./define-variant.nix + cat <