Add impure links module
This commit is contained in:
parent
96ed6c4c63
commit
d6495fe305
|
@ -16,12 +16,15 @@
|
|||
specialArgs = { inherit system inputs; };
|
||||
|
||||
modules = [
|
||||
(import ./modules/impurity.nix self)
|
||||
./modules/preserve-system.nix
|
||||
./modules/core.nix
|
||||
./modules/user
|
||||
./systems/lenovo.nix
|
||||
];
|
||||
};
|
||||
|
||||
lenovo-impure = self.nixosConfigurations.lenovo.extendModules { modules = [ { impurity.enable = true; } ]; };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
39
modules/impurity.nix
Normal file
39
modules/impurity.nix
Normal file
|
@ -0,0 +1,39 @@
|
|||
self: { lib, config, pkgs, ... }: with lib; let
|
||||
relativePath = path: assert types.path.check path;
|
||||
with builtins; strings.removePrefix ("${toString self}") (toString path);
|
||||
|
||||
impurityGroupEnabled = group: let
|
||||
impurityGroups = strings.splitString " " (builtins.getEnv "IMPURITY_GROUPS");
|
||||
in group == "" || builtins.elem group impurityGroups;
|
||||
|
||||
impurePath = let
|
||||
impurePathEnv = builtins.getEnv "IMPURITY_PATH";
|
||||
in if impurePathEnv == ""
|
||||
then throw "impurity.enable is true but IMPURITY_PATH is not set"
|
||||
else /. + impurePathEnv;
|
||||
|
||||
createImpurePath = path: impurePath + (relativePath path);
|
||||
in {
|
||||
options.impurity.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable impure symlinks";
|
||||
};
|
||||
|
||||
config._module.args.impurity = rec {
|
||||
groupedLink = groupspec: path:
|
||||
assert types.path.check path; let
|
||||
groups =
|
||||
if groupspec == null
|
||||
then [ "" ]
|
||||
else if (types.listOf types.string).check groupspec
|
||||
then groupspec
|
||||
else assert types.string.check groupspec;
|
||||
strings.splitString " " groupspec;
|
||||
in if config.impurity.enable && lists.any (group: impurityGroupEnabled group) groups
|
||||
then createImpurePath path
|
||||
else path;
|
||||
|
||||
link = path: groupedLink null path;
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue