nix!: remove modDir flake module

This commit is contained in:
Primrose 2024-12-21 12:30:06 +01:00
parent 1d7d2217ac
commit 291bd66d24
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA
3 changed files with 17 additions and 26 deletions

View file

@ -0,0 +1,98 @@
{
lib,
inputs,
withSystem,
...
}:
let
mkNixOS =
sharedModules:
{
hostname,
system,
modules ? [ ],
}:
inputs.nixpkgs.lib.nixosSystem {
specialArgs = {
inherit hostname;
};
modules = sharedModules { inherit hostname system; } ++ modules;
};
mkDarwin =
sharedModules:
{
hostname,
system,
modules ? [ ],
}:
inputs.nix-darwin.lib.darwinSystem {
specialArgs = {
inherit hostname;
};
modules = sharedModules { inherit hostname system; } ++ modules;
};
mkHomeManager =
sharedModules:
{
hostname,
system,
modules ? [ ],
}:
withSystem system (
{ pkgs, ... }:
inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = {
inherit hostname;
};
modules = sharedModules { inherit hostname system; } ++ modules;
}
);
many = func: builtins.mapAttrs (hostname: cfgs: func (cfgs // { inherit hostname; }));
maybePathOrDefault =
path: default:
if
lib.pathExists # Test directory/default.nix or just the file
(if lib.pathIsDirectory path then (lib.path.append path "default.nix") else path)
then
path
else
default;
mergeAttrsWith =
f: xs: ys:
builtins.foldl' (
acc: n: acc // (if acc ? ${n} then { ${n} = f xs.${n} ys.${n}; } else { ${n} = ys.${n}; })
) xs (builtins.attrNames ys);
modulesFromDir =
path:
lib.pipe (builtins.readDir path) [
(lib.filterAttrs (moduleName: _: moduleName != "default.nix"))
(lib.mapAttrs' (
moduleName: _: {
name = lib.strings.removeSuffix ".nix" moduleName;
value = lib.path.append path moduleName;
}
))
];
in
{
_module.args = {
inherit
many
mkNixOS
mkDarwin
mkHomeManager
maybePathOrDefault
mergeAttrsWith
modulesFromDir
;
};
}