infrastructure/meta/default.nix

46 lines
1.1 KiB
Nix
Raw Normal View History

###
# Metadata for the nodes. You can add custom attributes, they are
# accessible through the specialArg meta in the config.
2023-05-22 15:06:11 +02:00
let
###
# Transforms data from :
# {
# zone01 = [ node01 node02 ];
# zone02 = [ node03 ];
# }
# to :
# {
# node01 = zone01;
# node02 = zone01;
# node03 = zone02;
# }
locations = builtins.foldl'
(a: loc: a // loc)
{ }
(builtins.concatLists (builtins.attrValues (builtins.mapAttrs
(zone: builtins.map (n: { ${n} = zone; }))
infra)));
###
# Add computed data about the nodes :
# - zone
# - deployment tags
# - network information
mkNode = node: attrs: attrs // {
zone = locations.${node};
deployment = let old = attrs.deployment; in old // {
tags = (old.tags or [ ]) ++ [ "infra-${locations.${node}}" ];
targetHost = old.targetHost or (builtins.head network.${node}.addresses.public);
};
};
infra = import ./infrastructure.nix;
2023-05-22 15:06:11 +02:00
members = import ./members.nix;
network = import ./network.nix;
nodes = builtins.mapAttrs mkNode (import ./nodes.nix);
2023-05-22 15:06:11 +02:00
in
{ inherit infra members network nodes; }