introduce nexus templating via nib
This commit is contained in:
parent
e21bd210c9
commit
57963b9c16
3 changed files with 50 additions and 8 deletions
|
|
@ -14,6 +14,7 @@
|
||||||
{
|
{
|
||||||
this,
|
this,
|
||||||
sys,
|
sys,
|
||||||
|
nib,
|
||||||
lib,
|
lib,
|
||||||
deploy-rs,
|
deploy-rs,
|
||||||
...
|
...
|
||||||
|
|
@ -21,8 +22,10 @@
|
||||||
inherit
|
inherit
|
||||||
(builtins)
|
(builtins)
|
||||||
elem
|
elem
|
||||||
|
isAttrs
|
||||||
mapAttrs
|
mapAttrs
|
||||||
pathExists
|
pathExists
|
||||||
|
typeOf
|
||||||
;
|
;
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
@ -30,19 +33,52 @@
|
||||||
mapNodes
|
mapNodes
|
||||||
;
|
;
|
||||||
|
|
||||||
mkNexus' = config: rec {
|
inherit
|
||||||
nixosConfigurations = mapNodes config.nexus.nodes (
|
(nib.std)
|
||||||
|
getAttrOr
|
||||||
|
;
|
||||||
|
|
||||||
|
templateNexus = let
|
||||||
|
inherit
|
||||||
|
(nib.types)
|
||||||
|
Terminal
|
||||||
|
;
|
||||||
|
|
||||||
|
missing = msg: path:
|
||||||
|
Terminal (abort ''
|
||||||
|
Each Cerulean Nexus node is required to specify ${msg}!
|
||||||
|
Ensure `nexus.${path}` exists under your call to `cerulean.mkNexus`.
|
||||||
|
'');
|
||||||
|
in {
|
||||||
|
root = missing "the root directory for all cerulean nix modules." "root";
|
||||||
|
groups = missing "an list of all valid node group names." "groups";
|
||||||
|
nodes = Terminal {};
|
||||||
|
};
|
||||||
|
|
||||||
|
parseNexus = nexus:
|
||||||
|
if !(isAttrs nexus)
|
||||||
|
then
|
||||||
|
abort ''
|
||||||
|
Cerulean Nexus config must be provided as an attribute set, got "${typeOf nexus}" instead!
|
||||||
|
Ensure all the `nexus` declaration is an attribute set under your call to `cerulean.mkNexus`.
|
||||||
|
''
|
||||||
|
else nib.parse.overrideStruct templateNexus nexus;
|
||||||
|
|
||||||
|
mkNexus' = nexus': let
|
||||||
|
nexus = parseNexus nexus';
|
||||||
|
in rec {
|
||||||
|
nixosConfigurations = mapNodes nexus.nodes (
|
||||||
nodeName: node:
|
nodeName: node:
|
||||||
lib.nixosSystem {
|
lib.nixosSystem {
|
||||||
system = node.system;
|
system = node.system;
|
||||||
modules = let
|
modules = let
|
||||||
core' = config.root + "/hosts/${nodeName}";
|
core' = nexus.root + "/hosts/${nodeName}";
|
||||||
core =
|
core =
|
||||||
if pathExists core'
|
if pathExists core'
|
||||||
then core'
|
then core'
|
||||||
else core' + ".nix";
|
else core' + ".nix";
|
||||||
in
|
in
|
||||||
[core] ++ node.extraModules;
|
[core ../nixos-module] ++ node.extraModules;
|
||||||
|
|
||||||
# nix passes these to every single module
|
# nix passes these to every single module
|
||||||
specialArgs =
|
specialArgs =
|
||||||
|
|
@ -54,7 +90,7 @@
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
deploy.nodes = mapNodes config.nexus.nodes (nodeName: node: let
|
deploy.nodes = mapNodes nexus.nodes (nodeName: node: let
|
||||||
inherit
|
inherit
|
||||||
(node.deploy)
|
(node.deploy)
|
||||||
activationTimeout
|
activationTimeout
|
||||||
|
|
@ -107,6 +143,9 @@
|
||||||
checks = mapAttrs (system: deployLib: deployLib.deployChecks deploy) deploy-rs.lib;
|
checks = mapAttrs (system: deployLib: deployLib.deployChecks deploy) deploy-rs.lib;
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
mkNexus = outputs:
|
mkNexus = outputs': let
|
||||||
(mkNexus' outputs.cerulean) // (removeAttrs outputs ["cerulean"]);
|
autogen = mkNexus' <| getAttrOr "nexus" outputs' {};
|
||||||
|
outputs = removeAttrs outputs' ["nexus"];
|
||||||
|
in
|
||||||
|
autogen // outputs; # XXX: TODO: replace this with a deep merge
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,10 @@
|
||||||
in rec {
|
in rec {
|
||||||
# abstract node instance that stores all default values
|
# abstract node instance that stores all default values
|
||||||
templateNode = name: system: let
|
templateNode = name: system: let
|
||||||
Terminal = nib.types.Terminal;
|
inherit
|
||||||
|
(nib.types)
|
||||||
|
Terminal
|
||||||
|
;
|
||||||
|
|
||||||
missing = msg: path:
|
missing = msg: path:
|
||||||
Terminal (abort ''
|
Terminal (abort ''
|
||||||
Loading…
Add table
Add a link
Reference in a new issue