feat(lib/mkSystem): add profile suppoet

This commit adds the mkSystem function to simplify nixosSystem
creation and merge profile configs.
This commit is contained in:
Mohammad Rafiq 2025-07-06 18:44:36 +08:00
parent 90899b5d37
commit 5501c39e31
No known key found for this signature in database

View file

@ -7,13 +7,28 @@
let let
inherit (lib.trivial) pipe; inherit (lib.trivial) pipe;
inherit (lib.strings) removePrefix hasPrefix; inherit (lib.strings) removePrefix hasPrefix;
inherit (lib.attrsets) concatMapAttrs mapAttrs' filterAttrs; inherit (lib.attrsets)
concatMapAttrs
mapAttrs'
filterAttrs
mergeAttrsList
;
in
{
flake.lib = rec {
flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset;
mkSystem = mkSystem =
prefix: name: value: prefix: name: value:
let let
hostName = removePrefix prefix name; hostName = removePrefix prefix name;
hostConfig = value; hostConfig = value;
flakeConfig = config; flakeConfig = config;
mkProfileCfg =
profileList: # List of attrsets of nixos configs
pipe profileList [
(map flattenAttrs) # List of nixos configs
mergeAttrsList
];
in in
{ {
name = hostName; name = hostName;
@ -28,14 +43,11 @@ let
}; };
modules = [ modules = [
config.flake.profiles.nixos.common config.flake.profiles.nixos.common
(mkProfileCfg (value.profiles or [ ]))
(value.extraCfg or { }) (value.extraCfg or { })
] ++ (value.profiles or [ ]); ];
}; };
}; };
in
{
flake.lib = {
flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset;
extractConfigurations = extractConfigurations =
prefix: hosts: prefix: hosts:
pipe hosts [ pipe hosts [