Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -74,6 +76,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.
Expand Down Expand Up @@ -146,6 +150,7 @@ rec {
config = {
_module.args = {
inherit extendModules;
moduleType = type;
} // args;
};
};
Expand Down
5 changes: 5 additions & 0 deletions lib/tests/modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
====== module tests ======
$pass Pass
Expand Down
9 changes: 9 additions & 0 deletions lib/tests/modules/declare-variants.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ lib, moduleType, ... }:
let inherit (lib) mkOption types;
in
{
options.variants = mkOption {
type = types.lazyAttrsOf moduleType;
default = {};
};
}
22 changes: 22 additions & 0 deletions lib/tests/modules/define-variant.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ 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);
};
}