summaryrefslogtreecommitdiff
path: root/doctrine/lib/mk-module.nix
diff options
context:
space:
mode:
authorFabian Montero <fabian@posixlycorrect.com>2026-02-03 15:12:59 -0600
committerFabian Montero <fabian@posixlycorrect.com>2026-02-03 15:12:59 -0600
commit4a822c48da5a3aa4550fd0fad2697fd023c1810a (patch)
tree3ad3d1fc31c545daf0d1c221c5cefba83c6cea04 /doctrine/lib/mk-module.nix
parente44c6337d4557c9377b562e3687d24ef5e236974 (diff)
parent0f6a8aa22d9b554c211a9d77bbf4fefdcabc20d1 (diff)
Merge commit '974154ce2da0b60bdff5ae3c57e0490db58d9f0e'
Diffstat (limited to 'doctrine/lib/mk-module.nix')
-rw-r--r--doctrine/lib/mk-module.nix69
1 files changed, 43 insertions, 26 deletions
diff --git a/doctrine/lib/mk-module.nix b/doctrine/lib/mk-module.nix
index ffbe6bc..7a1de39 100644
--- a/doctrine/lib/mk-module.nix
+++ b/doctrine/lib/mk-module.nix
@@ -13,39 +13,56 @@
namespace ? doctrine.namespace,
passthru ? {},
}: let
- optionsSet = import options (passthru
- // {
- inherit config lib pkgs cfg name doctrine;
- });
+ patchArgs = args: args // passthru // {inherit cfg name doctrine;};
- configSet = import configFiles.${namespace} (passthru
- // {
- inherit config lib pkgs doctrine cfg;
- });
+ 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 {
- 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;
- }
- ]));
+ 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;
+ }
+ ]);
+ })
- options.${prefix}.${name} =
- lib.optionalAttrs (options != null && optionsSet ? ${namespace}) optionsSet.${namespace}
- // {
- enable = lib.mkEnableOption name;
- };
+ (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;
+ };
+ })
+ ];
}