summaryrefslogtreecommitdiff
path: root/doctrine/lib/mk-module.nix
blob: 79c24c5235e47f4ccfea515bfaecd0e9c3a9d48d (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
{
  name,
  hm ? null,
  sys ? null,
  options ? null,
  lib,
  config,
  pkgs,
  doctrine,
}: let
  optionsSet = import options {
    inherit config lib pkgs cfg name doctrine;
  };

  configSet = import configFiles.${doctrine.namespace} {
    inherit config lib pkgs doctrine cfg;
  };

  configFiles = lib.filterAttrs (k: v: v != null) {
    inherit sys hm;
  };

  cfg = config.${doctrine.prefix}.${name};
in {
  config =
    lib.optionalAttrs (configFiles ? ${doctrine.namespace})
    (lib.mkIf cfg.enable configSet);

  options = lib.optionalAttrs (options
    != null
    && optionsSet ? ${doctrine.namespace}) {
    ${doctrine.prefix}.${name} =
      optionsSet.${doctrine.namespace}
      // {
        enable = lib.mkEnableOption name;
      };
  };
}