major refactoring
argument self is now provided via recursion a naive implementation of host groups is added
This commit is contained in:
parent
be916c8674
commit
5c5f3fb65e
3 changed files with 183 additions and 105 deletions
|
|
@ -23,8 +23,12 @@
|
||||||
}: let
|
}: let
|
||||||
inherit
|
inherit
|
||||||
(builtins)
|
(builtins)
|
||||||
|
attrNames
|
||||||
|
concatStringsSep
|
||||||
elem
|
elem
|
||||||
|
getAttr
|
||||||
isAttrs
|
isAttrs
|
||||||
|
isFunction
|
||||||
mapAttrs
|
mapAttrs
|
||||||
pathExists
|
pathExists
|
||||||
typeOf
|
typeOf
|
||||||
|
|
@ -37,7 +41,7 @@
|
||||||
|
|
||||||
templateNexus = let
|
templateNexus = let
|
||||||
inherit
|
inherit
|
||||||
(nt.types)
|
(nt.naive.terminal)
|
||||||
Terminal
|
Terminal
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
@ -47,35 +51,112 @@
|
||||||
Ensure `nexus.${path}` exists under your call to `cerulean.mkNexus`.
|
Ensure `nexus.${path}` exists under your call to `cerulean.mkNexus`.
|
||||||
'');
|
'');
|
||||||
in {
|
in {
|
||||||
groups = missing "an list of all valid node group names." "groups";
|
groups = Terminal {};
|
||||||
overlays = [];
|
overlays = [];
|
||||||
nodes = Terminal {};
|
nodes = Terminal {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
parseGroups = groups: let
|
||||||
|
validGroup = g:
|
||||||
|
isAttrs g
|
||||||
|
|| throw ''
|
||||||
|
Cerulean Nexus groups must be provided as attribute sets, got "${typeOf g}" instead!
|
||||||
|
Ensure all the `groups` definitions are attribute sets under your call to `cerulean.mkNexus`.
|
||||||
|
'';
|
||||||
|
delegate = parent: g:
|
||||||
|
g
|
||||||
|
|> mapAttrs (name: value:
|
||||||
|
assert validGroup value;
|
||||||
|
(delegate g value)
|
||||||
|
// {
|
||||||
|
_name = name;
|
||||||
|
_parent = parent;
|
||||||
|
});
|
||||||
|
in
|
||||||
|
assert validGroup groups;
|
||||||
|
delegate null groups;
|
||||||
|
|
||||||
parseNexus = nexus:
|
parseNexus = nexus:
|
||||||
if ! isAttrs nexus
|
assert isAttrs nexus
|
||||||
then
|
|| abort ''
|
||||||
abort ''
|
|
||||||
Cerulean Nexus config must be provided as an attribute set, got "${typeOf nexus}" instead!
|
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`.
|
Ensure all the `nexus` declaration is an attribute set under your call to `cerulean.mkNexus`.
|
||||||
''
|
''; let
|
||||||
else nt.projectOnto templateNexus nexus;
|
base = nt.projectOnto templateNexus nexus;
|
||||||
|
in
|
||||||
|
# XXX: TODO: create a different version of nt.projectOnto that can actually
|
||||||
|
# XXX: TODO: handle applying a transformation to the result of each datapoint
|
||||||
|
base
|
||||||
|
// {
|
||||||
|
groups = parseGroups base.groups;
|
||||||
|
};
|
||||||
|
|
||||||
mkNexus' = root: nexus': let
|
parseDecl = outputsBuilder: let
|
||||||
nexus = parseNexus nexus';
|
decl = (
|
||||||
in rec {
|
if isFunction outputsBuilder
|
||||||
|
then outputsBuilder final # provide `self`
|
||||||
|
else
|
||||||
|
assert (isAttrs outputsBuilder)
|
||||||
|
|| abort ''
|
||||||
|
Cerulean declaration must be provided as an attribute set, got "${typeOf outputsBuilder}" instead!
|
||||||
|
Ensure your declaration is an attribute set or function under your call to `cerulean.mkNexus`.
|
||||||
|
''; outputsBuilder
|
||||||
|
);
|
||||||
|
|
||||||
|
final =
|
||||||
|
decl
|
||||||
|
// {
|
||||||
|
nexus = parseNexus (decl.nexus or {});
|
||||||
|
};
|
||||||
|
in
|
||||||
|
final;
|
||||||
|
|
||||||
|
# XXX: TODO: create a function in NixTypes that handles this instead
|
||||||
|
findImport = path:
|
||||||
|
if pathExists path
|
||||||
|
then path
|
||||||
|
else path + ".nix";
|
||||||
|
in {
|
||||||
|
mkNexus = root: outputsBuilder: let
|
||||||
|
decl = parseDecl outputsBuilder;
|
||||||
|
|
||||||
|
inherit
|
||||||
|
(decl)
|
||||||
|
nexus
|
||||||
|
;
|
||||||
|
customOutputs = removeAttrs decl ["nexus"];
|
||||||
|
|
||||||
|
outputs = rec {
|
||||||
nixosConfigurations = mapNodes nexus.nodes (
|
nixosConfigurations = mapNodes nexus.nodes (
|
||||||
nodeName: node:
|
nodeName: node:
|
||||||
lib.nixosSystem {
|
lib.nixosSystem {
|
||||||
system = node.system;
|
system = node.system;
|
||||||
modules = let
|
modules = let
|
||||||
host' = root + "/hosts/${nodeName}";
|
host = findImport (root + "/hosts/${nodeName}");
|
||||||
host =
|
# XXX: TODO: don't use a naive type for this (ie _name property)
|
||||||
if pathExists host'
|
# XXX: TODO: i really need NixTypes to be stable and use that instead
|
||||||
then host'
|
groups =
|
||||||
else host' + ".nix";
|
node.groups
|
||||||
|
|> map (group:
|
||||||
|
assert group ? _name
|
||||||
|
|| throw (let
|
||||||
|
got =
|
||||||
|
if ! isAttrs group
|
||||||
|
then toString group
|
||||||
|
else
|
||||||
|
group
|
||||||
|
|> attrNames
|
||||||
|
|> map (name: "${name} = <${typeOf (getAttr name group)}>;")
|
||||||
|
|> concatStringsSep " "
|
||||||
|
|> (x: "{ ${x} }");
|
||||||
|
in ''
|
||||||
|
Cerulean Nexus node "${nodeName}" is a member of a nonexistent group.
|
||||||
|
Got "${got}" of primitive type "${typeOf group}".
|
||||||
|
NOTE: Groups can be accessed via `self.groups.PATH.TO.YOUR.GROUP`
|
||||||
|
'');
|
||||||
|
findImport (root + "/groups/${group._name}"));
|
||||||
in
|
in
|
||||||
[../nixos-module host] ++ node.extraModules;
|
[../nixos-module host] ++ groups ++ node.extraModules;
|
||||||
|
|
||||||
# nix passes these to every single module
|
# nix passes these to every single module
|
||||||
specialArgs = let
|
specialArgs = let
|
||||||
|
|
@ -149,10 +230,6 @@
|
||||||
|
|
||||||
checks = mapAttrs (system: deployLib: deployLib.deployChecks deploy) deploy-rs.lib;
|
checks = mapAttrs (system: deployLib: deployLib.deployChecks deploy) deploy-rs.lib;
|
||||||
};
|
};
|
||||||
in {
|
|
||||||
mkNexus = root: outputs': let
|
|
||||||
autogen = mkNexus' root (outputs'.nexus or {});
|
|
||||||
outputs = removeAttrs outputs' ["nexus"];
|
|
||||||
in
|
in
|
||||||
autogen // outputs; # XXX: TODO: replace this with a deep merge
|
outputs // customOutputs;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,12 @@ 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
|
||||||
inherit
|
inherit
|
||||||
(nt.types)
|
(nt.naive.terminal)
|
||||||
Terminal
|
Terminal
|
||||||
;
|
;
|
||||||
in {
|
in {
|
||||||
system = "x86_64-linux"; # sane default (i hope...)
|
system = "x86_64-linux"; # sane default (i hope...)
|
||||||
|
groups = [];
|
||||||
extraModules = [];
|
extraModules = [];
|
||||||
specialArgs = Terminal {};
|
specialArgs = Terminal {};
|
||||||
overlays = [];
|
overlays = [];
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@
|
||||||
...
|
...
|
||||||
} @ inputs:
|
} @ inputs:
|
||||||
import ./cerulean
|
import ./cerulean
|
||||||
<| inputs
|
(inputs
|
||||||
// {
|
// {
|
||||||
inherit (nixpkgs) lib;
|
inherit (nixpkgs) lib;
|
||||||
inherit (nt) mix;
|
inherit (nt) mix;
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue