summaryrefslogtreecommitdiffstats
path: root/lib/tests/modules/lazy-attrsWith.nix
blob: bd214819c1111d84753e887c2dedbedc38717ebb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Check that AttrsWith { lazy = true; } is lazy
{ lib, ... }:
let
  inherit (lib) types mkOption;

  lazyAttrsOf = mkOption {
    # Same as lazyAttrsOf
    type = types.attrsWith {
      lazy = true;
      elemType = types.int;
    };
  };

  attrsOf = mkOption {
    # Same as lazyAttrsOf
    type = types.attrsWith {
      elemType = types.int;
    };
  };
in
{
  imports = [
    #  Module A
    (
      { ... }:
      {
        options.mergedLazyLazy = lazyAttrsOf;
        options.mergedLazyNonLazy = lazyAttrsOf;
        options.mergedNonLazyNonLazy = attrsOf;
      }
    )
    # Module B
    (
      { ... }:
      {
        options.mergedLazyLazy = lazyAttrsOf;
        options.mergedLazyNonLazy = attrsOf;
        options.mergedNonLazyNonLazy = attrsOf;
      }
    )
    # Result
    (
      { config, ... }:
      {
        # Can only evaluate if lazy
        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; };
      }
    )
  ];
}