modules: Add moduleType to module arguments

+3
lib/modules.nix
···
‘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.
···
config = {
_module.args = {
inherit extendModules;
+
moduleType = type;
} // args;
};
};
+5
lib/tests/modules.sh
···
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 <<EOF
====== module tests ======
$pass Pass
+9
lib/tests/modules/declare-variants.nix
···
+
{ lib, moduleType, ... }:
+
let inherit (lib) mkOption types;
+
in
+
{
+
options.variants = mkOption {
+
type = types.lazyAttrsOf moduleType;
+
default = {};
+
};
+
}
+22
lib/tests/modules/define-variant.nix
···
+
{ config, lib, ... }:
+
let inherit (lib) types mkOption attrNames;
+
in
+
{
+
options = {
+
attrs = mkOption { type = types.attrsOf lib.types.int; };
+
result = mkOption { };
+
resultFoo = mkOption { };
+
resultFooBar = mkOption { };
+
resultFooFoo = mkOption { };
+
};
+
config = {
+
attrs.a = 1;
+
variants.foo.attrs.b = 1;
+
variants.bar.attrs.y = 1;
+
variants.foo.variants.bar.attrs.z = 1;
+
variants.foo.variants.foo.attrs.c = 3;
+
resultFoo = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.attrs);
+
resultFooBar = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.variants.bar.attrs);
+
resultFooFoo = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.variants.foo.attrs);
+
};
+
}