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
|
{
# The first few arguments are implicitly passed by the 'close' helper
lib,
pkgs,
doctrine,
name,
config,
hm ? null,
sys ? null,
options ? null,
requires ? [],
prefix ? doctrine.prefix,
namespace ? doctrine.namespace,
passthru ? {},
}: let
patchArgs = args: args // passthru // {inherit cfg name doctrine;};
optionsSet = args: import options (patchArgs args);
configSet = args: import configFiles.${namespace} (patchArgs args);
configFiles = lib.filterAttrs (k: v: v != null) {
inherit sys hm;
};
cfg = config.${prefix}.${name};
hasConfig = configFiles ? ${namespace};
in {
imports = [
(args @ {
config,
modulesPath ? null,
lib,
pkgs,
...
}:
lib.optionalAttrs hasConfig {
config = lib.mkIf cfg.enable (lib.mkMerge [
(configSet args)
{
assertions =
map (dependency: {
assertion = cfg.enable -> config.${prefix}.${dependency}.enable;
message = "${prefix}.${name}.enable requires ${prefix}.${dependency}.enable";
})
requires;
}
]);
})
(args @ {
config,
modulesPath ? null,
lib,
pkgs,
...
}: let
hasOptions = options != null && optionsForArgs ? ${namespace};
optionsForArgs = optionsSet args;
in
lib.optionalAttrs (hasOptions || hasConfig) {
options.${prefix}.${name} =
lib.optionalAttrs hasOptions optionsForArgs.${namespace}
// {
enable = lib.mkEnableOption name;
};
})
];
}
|