trivionomicon/doctrine: have mk-module define config and options as separate modules

This commit is contained in:
Alejandro Soto 2026-01-31 10:35:30 -06:00
parent 8931cb43db
commit b802d4a2c8

View file

@ -13,26 +13,29 @@
namespace ? doctrine.namespace, namespace ? doctrine.namespace,
passthru ? {}, passthru ? {},
}: let }: let
optionsSet = import options (passthru patchArgs = args: args // passthru // {inherit cfg name doctrine;};
// {
inherit config lib pkgs cfg name doctrine;
});
configSet = import configFiles.${namespace} (passthru optionsSet = args: import options (patchArgs args);
// { configSet = args: import configFiles.${namespace} (patchArgs args);
inherit config lib pkgs doctrine cfg;
});
configFiles = lib.filterAttrs (k: v: v != null) { configFiles = lib.filterAttrs (k: v: v != null) {
inherit sys hm; inherit sys hm;
}; };
cfg = config.${prefix}.${name}; cfg = config.${prefix}.${name};
hasConfig = configFiles ? ${namespace};
in { in {
config = imports = [
lib.optionalAttrs (configFiles ? ${namespace}) (args @ {
(lib.mkIf cfg.enable (lib.mkMerge [ config,
configSet modulesPath ? null,
lib,
pkgs,
...
}:
lib.optionalAttrs hasConfig {
config = lib.mkIf cfg.enable (lib.mkMerge [
(configSet args)
{ {
assertions = assertions =
map (dependency: { map (dependency: {
@ -41,11 +44,25 @@ in {
}) })
requires; requires;
} }
])); ]);
})
(args @ {
config,
modulesPath ? null,
lib,
pkgs,
...
}: let
hasOptions = options != null && optionsForArgs ? ${namespace};
optionsForArgs = optionsSet args;
in
lib.optionalAttrs (hasOptions || hasConfig) {
options.${prefix}.${name} = options.${prefix}.${name} =
lib.optionalAttrs (options != null && optionsSet ? ${namespace}) optionsSet.${namespace} lib.optionalAttrs hasOptions optionsForArgs.${namespace}
// { // {
enable = lib.mkEnableOption name; enable = lib.mkEnableOption name;
}; };
})
];
} }