summary refs log tree commit diff
path: root/lib/tests/modules/deferred-module.nix
blob: d03c60b029bf12932fa773f524894de269cfed52 (plain) (blame)
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
{ lib, ... }:
let
  inherit (lib) types mkOption setDefaultModuleLocation;
  inherit (types) deferredModule lazyAttrsOf submodule str raw 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;
      };
    }

  ];
}