trivionomicon/doctrine: have mk-module define config and options as separate modules
This commit is contained in:
parent
8931cb43db
commit
b802d4a2c8
1 changed files with 43 additions and 26 deletions
|
|
@ -13,39 +13,56 @@
|
||||||
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,
|
||||||
assertions =
|
pkgs,
|
||||||
map (dependency: {
|
...
|
||||||
assertion = cfg.enable -> config.${prefix}.${dependency}.enable;
|
}:
|
||||||
message = "${prefix}.${name}.enable requires ${prefix}.${dependency}.enable";
|
lib.optionalAttrs hasConfig {
|
||||||
})
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
||||||
requires;
|
(configSet args)
|
||||||
}
|
{
|
||||||
]));
|
assertions =
|
||||||
|
map (dependency: {
|
||||||
|
assertion = cfg.enable -> config.${prefix}.${dependency}.enable;
|
||||||
|
message = "${prefix}.${name}.enable requires ${prefix}.${dependency}.enable";
|
||||||
|
})
|
||||||
|
requires;
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
})
|
||||||
|
|
||||||
options.${prefix}.${name} =
|
(args @ {
|
||||||
lib.optionalAttrs (options != null && optionsSet ? ${namespace}) optionsSet.${namespace}
|
config,
|
||||||
// {
|
modulesPath ? null,
|
||||||
enable = lib.mkEnableOption name;
|
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;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue