refactor(nixos): change hostSpec to define top level option

This commit is contained in:
Mohammad Rafiq 2025-07-06 04:18:21 +08:00
parent 30c0b3c804
commit 3e11c923ac
No known key found for this signature in database
3 changed files with 31 additions and 29 deletions

View file

@ -0,0 +1,28 @@
{ config, lib, ... }:
let
inherit (lib.trivial) pipe;
inherit (lib.attrsets) filterAttrs mapAttrs';
inherit (lib.strings) removePrefix hasPrefix;
prefix = "nixos/";
hosts = config.flake.hostSpec.hosts or { };
mkSystem =
name: value:
let
hostName = removePrefix prefix name;
in
{
name = hostName;
value = lib.nixosSystem {
modules = [
value
{ networking = { inherit hostName; }; }
];
};
};
in
{
flake.nixosConfigurations = pipe hosts [
(filterAttrs (name: _: hasPrefix prefix name))
(mapAttrs' mkSystem)
];
}