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:
parent
90899b5d37
commit
5501c39e31
1 changed files with 38 additions and 26 deletions
|
@ -7,35 +7,47 @@
|
||||||
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)
|
||||||
mkSystem =
|
concatMapAttrs
|
||||||
prefix: name: value:
|
mapAttrs'
|
||||||
let
|
filterAttrs
|
||||||
hostName = removePrefix prefix name;
|
mergeAttrsList
|
||||||
hostConfig = value;
|
;
|
||||||
flakeConfig = config;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
name = hostName;
|
|
||||||
value = lib.nixosSystem {
|
|
||||||
specialArgs = {
|
|
||||||
inherit
|
|
||||||
inputs
|
|
||||||
hostName
|
|
||||||
hostConfig
|
|
||||||
flakeConfig
|
|
||||||
;
|
|
||||||
};
|
|
||||||
modules = [
|
|
||||||
config.flake.profiles.nixos.common
|
|
||||||
(value.extraCfg or { })
|
|
||||||
] ++ (value.profiles or [ ]);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flake.lib = {
|
flake.lib = rec {
|
||||||
flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset;
|
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 = [
|
||||||
|
config.flake.profiles.nixos.common
|
||||||
|
(mkProfileCfg (value.profiles or [ ]))
|
||||||
|
(value.extraCfg or { })
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
extractConfigurations =
|
extractConfigurations =
|
||||||
prefix: hosts:
|
prefix: hosts:
|
||||||
pipe hosts [
|
pipe hosts [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue