summaryrefslogtreecommitdiffstats
path: root/lib/tests/modules/types-valueMeta.nix
blob: 3004898f112a64f9c30be11f834d20a6fe19cf32 (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
58
59
60
{ lib, ... }:
let
  inherit (lib) types mkOption;

  inherit (types)
    # attrsOf uses attrsWith internally
    attrsOf
    listOf
    submoduleOf
    str
    ;
in
{
  imports = [
    (
      { options, ... }:
      {
        # Should have an empty valueMeta
        options.str = mkOption {
          type = str;
        };

        # Should have some valueMeta which is an attribute set of the nested valueMeta
        options.attrsOf = mkOption {
          type = attrsOf str;
          default = {
            foo = "foo";
            bar = "bar";
          };
        };
        options.attrsOfResult = mkOption {
          default = builtins.attrNames options.attrsOf.valueMeta.attrs;
        };

        # Should have some valueMeta which is the list of the nested valueMeta of types.str
        # [ {} {} ]
        options.listOf = mkOption {
          type = listOf str;
          default = [
            "foo"
            "bar"
          ];
        };
        options.listOfResult = mkOption {
          default = builtins.length options.listOf.valueMeta.list;
        };

        # Should have some valueMeta which is the submodule evaluation
        # { _module, options, config, ...}
        options.submoduleOf = mkOption {
          type = submoduleOf {
            options.str = mkOption {
              type = str;
            };
          };
        };
      }
    )
  ];
}