feat(topology): render network addresses

This commit is contained in:
oddlama 2024-03-16 13:49:59 +01:00
parent 887115c96d
commit 25a864b1e8
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
8 changed files with 31 additions and 23 deletions

View file

@ -0,0 +1,3 @@
{config, ...}: {
topology.id = config.node.name;
}

View file

@ -24,6 +24,7 @@
./config/secrets.nix ./config/secrets.nix
./config/ssh.nix ./config/ssh.nix
./config/system.nix ./config/system.nix
./config/topology.nix
./config/users.nix ./config/users.nix
./acme-wildcard.nix ./acme-wildcard.nix

View file

@ -1,2 +0,0 @@
{
}

View file

@ -1,2 +0,0 @@
{
}

View file

@ -1,2 +0,0 @@
{
}

View file

@ -73,7 +73,7 @@ in {
network = networkId wgName; network = networkId wgName;
virtual = true; virtual = true;
physicalConnections = flip map connectedPeers (peer: { physicalConnections = flip map connectedPeers (peer: {
node = peer; node = inputs.self.nodes.${peer}.config.topology.id;
interface = (wgCfgOf peer).linkName; interface = (wgCfgOf peer).linkName;
}); });
}; };

View file

@ -89,7 +89,7 @@ in
interface: interface:
[ [
{ {
assertion = config.networks ? ${interface.network}; assertion = interface.network != null -> config.networks ? ${interface.network};
message = "topology: nodes.${node.id}.interfaces.${interface.id} refers to an unknown network '${interface.network}'"; message = "topology: nodes.${node.id}.interfaces.${interface.id} refers to an unknown network '${interface.network}'";
} }
] ]

View file

@ -8,6 +8,7 @@
(lib) (lib)
attrValues attrValues
concatLines concatLines
optionalString
; ;
#toD2 = _nodeName: node: '' #toD2 = _nodeName: node: ''
@ -29,25 +30,34 @@
#''; #'';
netToD2 = net: '' netToD2 = net: ''
${net.id}: |md ${net.id}: ${net.name} {
# ${net.name} info: |md
${net.cidrv4} ${net.cidrv4}
${net.cidrv6} ${net.cidrv6}
| |
}
''; '';
nodeInterfaceToD2 = node: interface: '' nodeInterfaceToD2 = node: interface:
${node.id}.${interface.id}: |md ''
## ${interface.id} ${node.id}.${interface.id}: ${interface.id} {
info: |md
${toString interface.mac}
${toString interface.addresses}
${toString interface.gateways}
| |
}
${node.id}.${interface.id} -> ${interface.network} ''
+ optionalString (interface.network != null) ''
${node.id}.${interface.id} -- ${interface.network}
''; '';
# TODO: deduplicate first
#+ concatLines (flip map interface.physicalConnections (x: ''
# ${node.id}.${interface.id} -- ${x.node}.${x.interface}
#''));
nodeToD2 = node: '' nodeToD2 = node: ''
${node.id}: |md ${node.id}: ${node.name} {}
# ${node.name}
|
${concatLines (map (nodeInterfaceToD2 node) (attrValues node.interfaces))} ${concatLines (map (nodeInterfaceToD2 node) (attrValues node.interfaces))}
''; '';