feat: massive refactor
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
{ lib, inputs }:
|
||||
lib.extend (
|
||||
self: super: {
|
||||
my = import ./my.nix { lib = self; };
|
||||
umport = import ./umport.nix { lib = self; };
|
||||
inherit (inputs.home-manager.lib) hm;
|
||||
haumea = inputs.haumea.lib;
|
||||
|
||||
102
lib/my.nix
102
lib/my.nix
@@ -1,102 +0,0 @@
|
||||
{ lib }:
|
||||
|
||||
{
|
||||
makeSwitch =
|
||||
{
|
||||
default ? false,
|
||||
config,
|
||||
optionPath,
|
||||
optionName,
|
||||
config',
|
||||
}:
|
||||
let
|
||||
cfg = lib.getAttrFromPath optionPath config.my;
|
||||
in
|
||||
{
|
||||
options.my = lib.setAttrByPath optionPath {
|
||||
enable = (lib.mkEnableOption optionName) // {
|
||||
inherit default;
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable config';
|
||||
};
|
||||
|
||||
makeHomePackageConfig =
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
packageName,
|
||||
packagePath,
|
||||
optionPath,
|
||||
extraConfig ? { },
|
||||
}:
|
||||
lib.my.makeSwitch {
|
||||
inherit config optionPath;
|
||||
optionName = packageName;
|
||||
config' = lib.mkMerge [
|
||||
{
|
||||
my.hm.home.packages = [ (lib.getAttrFromPath packagePath pkgs) ];
|
||||
}
|
||||
extraConfig
|
||||
];
|
||||
};
|
||||
|
||||
makeHomeProgramConfig =
|
||||
{
|
||||
config,
|
||||
programName,
|
||||
optionPath,
|
||||
extraConfig ? { },
|
||||
}:
|
||||
lib.my.makeSwitch {
|
||||
inherit config optionPath;
|
||||
optionName = programName;
|
||||
|
||||
config' = lib.mkMerge [
|
||||
{
|
||||
my.hm.programs = lib.setAttrByPath [ programName "enable" ] true;
|
||||
}
|
||||
extraConfig
|
||||
];
|
||||
};
|
||||
|
||||
makeNixosPackageConfig =
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
packageName,
|
||||
packagePath,
|
||||
optionPath,
|
||||
extraConfig ? { },
|
||||
}:
|
||||
lib.my.makeSwitch {
|
||||
inherit config optionPath;
|
||||
optionName = packageName;
|
||||
config' = lib.mkMerge [
|
||||
{
|
||||
environment.systemPackages = [ (lib.getAttrFromPath packagePath pkgs) ];
|
||||
}
|
||||
extraConfig
|
||||
];
|
||||
};
|
||||
|
||||
makeNixosProgramConfig =
|
||||
{
|
||||
config,
|
||||
programName,
|
||||
optionPath,
|
||||
extraConfig ? { },
|
||||
}:
|
||||
lib.my.makeSwitch {
|
||||
inherit config optionPath;
|
||||
optionName = programName;
|
||||
|
||||
config' = lib.mkMerge [
|
||||
{
|
||||
programs = lib.setAttrByPath [ programName "enable" ] true;
|
||||
}
|
||||
extraConfig
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -13,6 +13,7 @@ let
|
||||
paths ? [ ],
|
||||
include ? [ ],
|
||||
exclude ? [ ],
|
||||
extraExcludePredicate ? _: true,
|
||||
recursive ? true,
|
||||
}:
|
||||
with lib;
|
||||
@@ -22,23 +23,22 @@ let
|
||||
excludedDirs = filter (path: pathIsDirectory path) exclude;
|
||||
isExcluded =
|
||||
path:
|
||||
if elem path excludedFiles then
|
||||
true
|
||||
else
|
||||
(filter (excludedDir: lib.path.hasPrefix excludedDir path) excludedDirs) != [ ];
|
||||
(elem path excludedFiles)
|
||||
|| ((filter (excludedDir: lib.path.hasPrefix excludedDir path) excludedDirs) != [ ])
|
||||
|| extraExcludePredicate path;
|
||||
in
|
||||
unique (
|
||||
(filter
|
||||
(file: pathIsRegularFile file && hasSuffix ".nix" (builtins.toString file) && !isExcluded file)
|
||||
(
|
||||
concatMap (
|
||||
_path:
|
||||
path:
|
||||
if recursive then
|
||||
toList _path
|
||||
toList path
|
||||
else
|
||||
mapAttrsToList (
|
||||
name: type: _path + (if type == "directory" then "/${name}/default.nix" else "/${name}")
|
||||
) (builtins.readDir _path)
|
||||
name: type: path + (if type == "directory" then "/${name}/default.nix" else "/${name}")
|
||||
) (builtins.readDir path)
|
||||
) (unique (if path == null then paths else [ path ] ++ paths))
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user