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

View file

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