refactor(nixos): move nixosSystem config to lib

Moves the nixosSystem configuration logic to a library function for reuse.
This commit is contained in:
Mohammad Rafiq 2025-07-06 18:27:28 +08:00
parent 61064b955d
commit 3c4bfeece9
No known key found for this signature in database
2 changed files with 42 additions and 40 deletions

View file

@ -1,44 +1,9 @@
{
config,
lib,
inputs,
...
}:
{ config, ... }:
let
inherit (lib.trivial) pipe;
inherit (lib.attrsets) filterAttrs mapAttrs';
inherit (lib.strings) removePrefix hasPrefix;
inherit (cfg.lib) extractConfigurations;
cfg = config.flake;
prefix = "nixos/";
hosts = cfg.hostSpec.hosts or { };
mkSystem =
name: value:
let
hostName = removePrefix prefix name;
hostConfig = value;
flakeConfig = config;
in
{
name = hostName;
value = lib.nixosSystem {
specialArgs = {
inherit
inputs
hostName
hostConfig
flakeConfig
;
};
modules = [
cfg.profiles.nixos.common
(value.extraCfg or { })
] ++ (value.profiles or [ ]);
};
};
in
{
flake.nixosConfigurations = pipe hosts [
(filterAttrs (name: _: hasPrefix prefix name))
(mapAttrs' mkSystem)
];
flake.nixosConfigurations = extractConfigurations "nixos/" hosts;
}