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,
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
imports = [
(args @ {
config,
modulesPath ? null,
lib,
pkgs,
...
}:
lib.optionalAttrs hasConfig {
config = lib.mkIf cfg.enable (lib.mkMerge [
(configSet args)
{
assertions =
map (dependency: {
@ -41,11 +44,25 @@ in {
})
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 (options != null && optionsSet ? ${namespace}) optionsSet.${namespace}
lib.optionalAttrs hasOptions optionsForArgs.${namespace}
// {
enable = lib.mkEnableOption name;
};
})
];
}