refactor: rename modules directory to nix
This commit is contained in:
parent
5501c39e31
commit
e884735f25
13 changed files with 1 additions and 1 deletions
58
nix/lib/default.nix
Normal file
58
nix/lib/default.nix
Normal file
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib.trivial) pipe;
|
||||
inherit (lib.strings) removePrefix hasPrefix;
|
||||
inherit (lib.attrsets)
|
||||
concatMapAttrs
|
||||
mapAttrs'
|
||||
filterAttrs
|
||||
mergeAttrsList
|
||||
;
|
||||
in
|
||||
{
|
||||
flake.lib = rec {
|
||||
flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset;
|
||||
mkSystem =
|
||||
prefix: name: value:
|
||||
let
|
||||
hostName = removePrefix prefix name;
|
||||
hostConfig = value;
|
||||
flakeConfig = config;
|
||||
mkProfileCfg =
|
||||
profileList: # List of attrsets of nixos configs
|
||||
pipe profileList [
|
||||
(map flattenAttrs) # List of nixos configs
|
||||
mergeAttrsList
|
||||
];
|
||||
in
|
||||
{
|
||||
name = hostName;
|
||||
value = lib.nixosSystem {
|
||||
specialArgs = {
|
||||
inherit
|
||||
inputs
|
||||
hostName
|
||||
hostConfig
|
||||
flakeConfig
|
||||
;
|
||||
};
|
||||
modules = [
|
||||
config.flake.profiles.nixos.common
|
||||
(mkProfileCfg (value.profiles or [ ]))
|
||||
(value.extraCfg or { })
|
||||
];
|
||||
};
|
||||
};
|
||||
extractConfigurations =
|
||||
prefix: hosts:
|
||||
pipe hosts [
|
||||
(filterAttrs (name: _: hasPrefix prefix name))
|
||||
(mapAttrs' (mkSystem prefix))
|
||||
];
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue