2023-08-19 22:54:14 -06:00
|
|
|
lib: config: pathStr: default: configAttrs:
|
|
|
|
let
|
|
|
|
|
|
|
|
pathToAttrSet = str: value:
|
|
|
|
let
|
|
|
|
parts = lib.splitString "." str;
|
|
|
|
in
|
|
|
|
if lib.length parts == 1 then
|
|
|
|
{ ${lib.head parts} = value; }
|
|
|
|
else
|
|
|
|
{ ${lib.head parts} = pathToAttrSet (lib.concatStringsSep "." (lib.tail parts)) value; };
|
|
|
|
|
|
|
|
optionsSet = pathToAttrSet pathStr {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
inherit default;
|
|
|
|
type = lib.types.bool;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-08-20 04:25:58 -06:00
|
|
|
cfg = lib.attrByPath (lib.splitString "." pathStr) { enable = false; } config;
|
2023-08-19 22:54:14 -06:00
|
|
|
|
2023-08-20 02:54:19 -06:00
|
|
|
# Extract 'imports' from configAttrs, if it exists
|
|
|
|
importsAttr = if configAttrs ? imports then configAttrs.imports else [];
|
|
|
|
# Remove 'imports' from configAttrs
|
|
|
|
configAttrsWithoutImports = lib.attrsets.removeAttrs configAttrs ["imports"];
|
|
|
|
|
2023-08-19 22:54:14 -06:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = optionsSet;
|
2023-08-20 02:54:19 -06:00
|
|
|
config = lib.mkIf cfg.enable configAttrsWithoutImports;
|
|
|
|
imports = importsAttr;
|
2023-08-19 22:54:14 -06:00
|
|
|
}
|