diff options
Diffstat (limited to 'trivionomicon/doctrine/lib/mk-module.nix')
| -rw-r--r-- | trivionomicon/doctrine/lib/mk-module.nix | 68 |
1 files changed, 68 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..7a1de39 --- /dev/null +++ b/trivionomicon/doctrine/lib/mk-module.nix @@ -0,0 +1,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; + }; + }) + ]; +} |
