summaryrefslogtreecommitdiffstats
path: root/lib/tests/modules/deferred-module.nix
blob: e14afb54f2132ab33b4817b9662ebf83ef812c62 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{ lib, ... }:
let
  inherit (lib) types mkOption;
  inherit (types)
    deferredModule
    lazyAttrsOf
    submodule
    str
    enum
    ;
in
{
  imports = [
    # generic module, declaring submodules:
    #   - nodes.<name>
    #   - default
    # where all nodes include the default
    (
      { 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.
          '';
        };
      }
    )

    {
      _file = "default-1.nix";
      default =
        { config, ... }:
        {
          options.settingsDict = lib.mkOption {
            type = lazyAttrsOf str;
            default = { };
          };
          options.bottom = lib.mkOption { type = enum [ ]; };
        };
    }

    {
      _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";
      nodes.foo =
        { config, ... }:
        {
          settingsDict.c = config.settingsDict.a;
        };
    }

  ];
}