core/lib/tests/modules/deferred-module.nix

78 lines
1.5 KiB
Nix
Raw Normal View History

2024-05-01 22:14:04 +00:00
{ lib, ... }:
let
inherit (lib) types mkOption setDefaultModuleLocation;
2024-06-30 08:16:52 +00:00
inherit (types)
deferredModule
lazyAttrsOf
submodule
str
raw
enum
;
2024-05-01 22:14:04 +00:00
in
{
imports = [
# generic module, declaring submodules:
# - nodes.<name>
# - default
# where all nodes include the default
2024-06-30 08:16:52 +00:00
(
{ config, ... }:
{
_file = "generic.nix";
options.nodes = mkOption {
type = lazyAttrsOf (submodule {
imports = [ config.default ];
});
default = { };
};
options.default = mkOption {
type = deferredModule;
default = { };
description = ''
Module that is included in all nodes.
'';
};
}
)
2024-05-01 22:14:04 +00:00
{
_file = "default-1.nix";
2024-06-30 08:16:52 +00:00
default =
{ config, ... }:
{
options.settingsDict = lib.mkOption {
type = lazyAttrsOf str;
default = { };
};
options.bottom = lib.mkOption { type = enum [ ]; };
};
2024-05-01 22:14:04 +00:00
}
{
_file = "default-a-is-b.nix";
default = ./define-settingsDict-a-is-b.nix;
}
{
_file = "nodes-foo.nix";
nodes.foo.settingsDict.b = "beta";
}
{
_file = "the-file-that-contains-the-bad-config.nix";
default.bottom = "bogus";
}
{
_file = "nodes-foo-c-is-a.nix";
2024-06-30 08:16:52 +00:00
nodes.foo =
{ config, ... }:
{
settingsDict.c = config.settingsDict.a;
};
2024-05-01 22:14:04 +00:00
}
];
}