forked from colonelpanic/dotfiles
[NixOS] Add make-enable to control nixos modules with configuration
This commit is contained in:
26
nixos/make-enable.nix
Normal file
26
nixos/make-enable.nix
Normal file
@@ -0,0 +1,26 @@
|
||||
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; defaulted = true; } config;
|
||||
|
||||
in
|
||||
{
|
||||
options = optionsSet;
|
||||
config = lib.mkIf cfg.enable configAttrs;
|
||||
}
|
||||
Reference in New Issue
Block a user