refactor(nixos): move nixosSystem config to lib
Moves the nixosSystem configuration logic to a library function for reuse.
This commit is contained in:
parent
c9636b0bfa
commit
90899b5d37
2 changed files with 42 additions and 40 deletions
|
@ -1,44 +1,9 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
{ config, ... }:
|
||||
let
|
||||
inherit (lib.trivial) pipe;
|
||||
inherit (lib.attrsets) filterAttrs mapAttrs';
|
||||
inherit (lib.strings) removePrefix hasPrefix;
|
||||
inherit (cfg.lib) extractConfigurations;
|
||||
cfg = config.flake;
|
||||
prefix = "nixos/";
|
||||
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
|
||||
flakeConfig
|
||||
;
|
||||
};
|
||||
modules = [
|
||||
cfg.profiles.nixos.common
|
||||
(value.extraCfg or { })
|
||||
] ++ (value.profiles or [ ]);
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
flake.nixosConfigurations = pipe hosts [
|
||||
(filterAttrs (name: _: hasPrefix prefix name))
|
||||
(mapAttrs' mkSystem)
|
||||
];
|
||||
flake.nixosConfigurations = extractConfigurations "nixos/" hosts;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,46 @@
|
|||
{ lib, ... }:
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib.attrsets) concatMapAttrs;
|
||||
inherit (lib.trivial) pipe;
|
||||
inherit (lib.strings) removePrefix hasPrefix;
|
||||
inherit (lib.attrsets) concatMapAttrs mapAttrs' filterAttrs;
|
||||
mkSystem =
|
||||
prefix: name: value:
|
||||
let
|
||||
hostName = removePrefix prefix name;
|
||||
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
|
||||
{
|
||||
flake.lib = {
|
||||
flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset;
|
||||
extractConfigurations =
|
||||
prefix: hosts:
|
||||
pipe hosts [
|
||||
(filterAttrs (name: _: hasPrefix prefix name))
|
||||
(mapAttrs' (mkSystem prefix))
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue