feat(nixos): pass flakeConfig to nixosSystem specialArgs

This commit is contained in:
Mohammad Rafiq 2025-07-06 07:31:48 +08:00
parent 88318c2e39
commit c9636b0bfa
No known key found for this signature in database
2 changed files with 14 additions and 6 deletions

View file

@ -8,20 +8,29 @@ let
inherit (lib.trivial) pipe;
inherit (lib.attrsets) filterAttrs mapAttrs';
inherit (lib.strings) removePrefix hasPrefix;
cfg = config.flake;
prefix = "nixos/";
hosts = config.flake.hostSpec.hosts or { };
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; };
specialArgs = {
inherit
inputs
hostName
hostConfig
flakeConfig
;
};
modules = [
config.flake.profiles.nixos.common
cfg.profiles.nixos.common
(value.extraCfg or { })
] ++ (value.profiles or [ ]);
};

View file

@ -1,10 +1,9 @@
{ lib, ... }:
let
inherit (lib.modules) mkMerge;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.attrsets) concatMapAttrs;
in
{
flake.lib = {
flattenAttrs = attrset: mkMerge (mapAttrsToList (_: v: v) attrset);
flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset;
};
}