2024-11-09 10:22:25 +00:00
|
|
|
# Check that AttrsWith { lazy = true; } is lazy
|
|
|
|
{ lib, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib) types mkOption;
|
2024-11-25 15:06:23 +00:00
|
|
|
|
|
|
|
lazyAttrsOf = mkOption {
|
|
|
|
# Same as lazyAttrsOf
|
|
|
|
type = types.attrsWith {
|
|
|
|
lazy = true;
|
|
|
|
elemType = types.int;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
attrsOf = mkOption {
|
|
|
|
# Same as lazyAttrsOf
|
|
|
|
type = types.attrsWith {
|
|
|
|
elemType = types.int;
|
|
|
|
};
|
|
|
|
};
|
2024-11-09 10:22:25 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
# Module A
|
|
|
|
(
|
|
|
|
{ ... }:
|
|
|
|
{
|
2024-11-25 15:06:23 +00:00
|
|
|
options.mergedLazyLazy = lazyAttrsOf;
|
|
|
|
options.mergedLazyNonLazy = lazyAttrsOf;
|
|
|
|
options.mergedNonLazyNonLazy = attrsOf;
|
2024-11-09 10:22:25 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
# Module B
|
|
|
|
(
|
|
|
|
{ ... }:
|
|
|
|
{
|
2024-11-25 15:06:23 +00:00
|
|
|
options.mergedLazyLazy = lazyAttrsOf;
|
|
|
|
options.mergedLazyNonLazy = attrsOf;
|
|
|
|
options.mergedNonLazyNonLazy = attrsOf;
|
2024-11-09 10:22:25 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
# Result
|
|
|
|
(
|
|
|
|
{ config, ... }:
|
|
|
|
{
|
|
|
|
# Can only evaluate if lazy
|
2024-11-25 15:06:23 +00:00
|
|
|
config.mergedLazyLazy.bar = config.mergedLazyLazy.baz + 1;
|
|
|
|
config.mergedLazyLazy.baz = 10;
|
|
|
|
options.lazyResult = mkOption { default = config.mergedLazyLazy.bar; };
|
|
|
|
|
|
|
|
# Can not only evaluate if not lazy
|
|
|
|
config.mergedNonLazyNonLazy.bar = config.mergedNonLazyNonLazy.baz + 1;
|
|
|
|
config.mergedNonLazyNonLazy.baz = 10;
|
|
|
|
options.nonLazyResult = mkOption { default = config.mergedNonLazyNonLazy.bar; };
|
2024-11-09 10:22:25 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
];
|
|
|
|
}
|