refactor: rename modules directory to nix

This commit is contained in:
Mohammad Rafiq 2025-07-06 19:11:49 +08:00
parent 5501c39e31
commit e884735f25
No known key found for this signature in database
13 changed files with 1 additions and 1 deletions

58
nix/lib/default.nix Normal file
View 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))
];
};
}