refactor(nixos): simplify configurations.nix and lib

This commit refactors configurations.nix and lib/default.nix by removing the
extractConfigurations function and related code from lib/default.nix,
and moving the NixOS system building logic directly into configurations.nix.
It also changes the structure of hosts in manifest.nix to use a
hosts.nixos attribute.
This commit is contained in:
Mohammad Rafiq 2025-07-07 06:41:53 +08:00
parent 94728cdc83
commit f71c65f639
No known key found for this signature in database
3 changed files with 32 additions and 59 deletions

View file

@ -1,59 +1,9 @@
{
lib,
config,
inputs,
...
}:
{ lib, ... }:
let
cfg = config.flake;
inherit (lib.trivial) pipe;
inherit (lib.strings) removePrefix hasPrefix;
inherit (lib.attrsets)
concatMapAttrs
mapAttrs'
filterAttrs
mergeAttrsList
;
inherit (lib.attrsets) concatMapAttrs;
in
{
flake.lib = rec {
flake.lib = {
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 = [
(flattenAttrs cfg.modules.nixos)
(mkProfileCfg (value.profiles or [ ]))
(value.extraCfg or { })
];
};
};
extractConfigurations =
prefix: hosts:
pipe hosts [
(filterAttrs (name: _: hasPrefix prefix name))
(mapAttrs' (mkSystem prefix))
];
};
}