-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmake-enable.nix
More file actions
29 lines (26 loc) · 873 Bytes
/
Copy pathmake-enable.nix
File metadata and controls
29 lines (26 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
};
};
cfg = lib.attrByPath (lib.splitString "." pathStr) {enable = false;} config;
# 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"];
in {
options = optionsSet;
config = lib.mkIf cfg.enable configAttrsWithoutImports;
imports = importsAttr;
}