diff options
Diffstat (limited to 'trivionomicon/doctrine/lib/mk-module.nix')
| -rw-r--r-- | trivionomicon/doctrine/lib/mk-module.nix | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/trivionomicon/doctrine/lib/mk-module.nix b/trivionomicon/doctrine/lib/mk-module.nix new file mode 100644 index 0000000..f76ccfe --- /dev/null +++ b/trivionomicon/doctrine/lib/mk-module.nix @@ -0,0 +1,48 @@ +{ + # 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, +}: let + optionsSet = import options { + inherit config lib pkgs cfg name doctrine; + }; + + configSet = import configFiles.${namespace} { + inherit config lib pkgs doctrine cfg; + }; + + configFiles = lib.filterAttrs (k: v: v != null) { + inherit sys hm; + }; + + cfg = config.${prefix}.${name}; +in { + config = + lib.optionalAttrs (configFiles ? ${namespace}) + (lib.mkIf cfg.enable (lib.mkMerge [ + configSet + { + assertions = + map (dependency: { + assertion = cfg.enable -> config.${prefix}.${dependency}.enable; + message = "${prefix}.${name}.enable requires ${prefix}.${dependency}.enable"; + }) + requires; + } + ])); + + options.${prefix}.${name} = + lib.optionalAttrs (options != null && optionsSet ? ${namespace}) optionsSet.${namespace} + // { + enable = lib.mkEnableOption name; + }; +} |
