pantheon/modules/lib/default.nix
Mohammad Rafiq 90899b5d37
refactor(nixos): move nixosSystem config to lib
Moves the nixosSystem configuration logic to a library function for reuse.
2025-07-07 17:42:30 +08:00

46 lines
961 B
Nix

{
lib,
config,
inputs,
...
}:
let
inherit (lib.trivial) pipe;
inherit (lib.strings) removePrefix hasPrefix;
inherit (lib.attrsets) concatMapAttrs mapAttrs' filterAttrs;
mkSystem =
prefix: name: value:
let
hostName = removePrefix prefix name;
hostConfig = value;
flakeConfig = config;
in
{
name = hostName;
value = lib.nixosSystem {
specialArgs = {
inherit
inputs
hostName
hostConfig
flakeConfig
;
};
modules = [
config.flake.profiles.nixos.common
(value.extraCfg or { })
] ++ (value.profiles or [ ]);
};
};
in
{
flake.lib = {
flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset;
extractConfigurations =
prefix: hosts:
pipe hosts [
(filterAttrs (name: _: hasPrefix prefix name))
(mapAttrs' (mkSystem prefix))
];
};
}