mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-11 07:10:39 +02:00
feat(topology): add interface port labels
This commit is contained in:
parent
b822b4e812
commit
f24fd89ae5
10 changed files with 103 additions and 109 deletions
BIN
dlink-dgs1016d.png
Normal file
BIN
dlink-dgs1016d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 243 KiB |
BIN
dlink-dgs105.png
Normal file
BIN
dlink-dgs105.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 372 KiB |
79
flake.nix
79
flake.nix
|
@ -187,30 +187,12 @@
|
||||||
renderer = "elk";
|
renderer = "elk";
|
||||||
nixosConfigurations = self.nodes;
|
nixosConfigurations = self.nodes;
|
||||||
|
|
||||||
nodes.fritzbox = {
|
|
||||||
name = "FritzBox";
|
|
||||||
deviceType = "router";
|
|
||||||
hardware.image = ./fritzbox.png;
|
|
||||||
# interfaces.wan0.network = "internet";
|
|
||||||
interfaces.wan0 = {};
|
|
||||||
interfaces.lan0.physicalConnections = [
|
|
||||||
{
|
|
||||||
node = "ward";
|
|
||||||
interface = "wan";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
node = "sire";
|
|
||||||
interface = "lan";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
nodes.internet = {
|
nodes.internet = {
|
||||||
name = "Internet";
|
name = "Internet";
|
||||||
deviceType = "internet";
|
deviceType = "internet";
|
||||||
hardware.image = ./cloud.svg;
|
hardware.image = ./cloud.svg;
|
||||||
# interfaces.wan0.network = "internet";
|
# interfaces.eth0.network = "internet";
|
||||||
interfaces.wan0.physicalConnections = [
|
interfaces.eth0.physicalConnections = [
|
||||||
{
|
{
|
||||||
node = "fritzbox";
|
node = "fritzbox";
|
||||||
interface = "wan0";
|
interface = "wan0";
|
||||||
|
@ -222,6 +204,63 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
nodes.fritzbox = {
|
||||||
|
name = "FritzBox";
|
||||||
|
deviceType = "router";
|
||||||
|
hardware.image = ./fritzbox.png;
|
||||||
|
# interfaces.wan0.network = "internet";
|
||||||
|
interfaces.wan0 = {};
|
||||||
|
interfaces.eth0.physicalConnections = [
|
||||||
|
{
|
||||||
|
node = "ward";
|
||||||
|
interface = "wan";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
nodes.switch-attic = {
|
||||||
|
name = "Switch Attic";
|
||||||
|
deviceType = "switch";
|
||||||
|
hardware.image = ./dlink-dgs1016d.png;
|
||||||
|
interfaces.eth0.physicalConnections = [
|
||||||
|
{
|
||||||
|
node = "ward";
|
||||||
|
interface = "lan";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
interfaces.eth1.physicalConnections = [
|
||||||
|
{
|
||||||
|
node = "sire";
|
||||||
|
interface = "lan";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
interfaces.eth2 = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
nodes.switch-bedroom-1 = {
|
||||||
|
name = "Switch Bedroom 1";
|
||||||
|
deviceType = "switch";
|
||||||
|
hardware.image = ./dlink-dgs105.png;
|
||||||
|
interfaces.eth0.physicalConnections = [
|
||||||
|
{
|
||||||
|
node = "switch-attic";
|
||||||
|
interface = "eth2";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
interfaces.eth1.physicalConnections = [
|
||||||
|
{
|
||||||
|
node = "kroma";
|
||||||
|
interface = "lan1";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
interfaces.eth2.physicalConnections = [
|
||||||
|
{
|
||||||
|
node = "nom";
|
||||||
|
interface = "lan1";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
#nodes.fritzbox-no-img = {
|
#nodes.fritzbox-no-img = {
|
||||||
# name = "FritzBox No HImg";
|
# name = "FritzBox No HImg";
|
||||||
# deviceType = "router";
|
# deviceType = "router";
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
./kea.nix
|
./kea.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
topology.self.hardware.image = ../../odroid-h3.png;
|
||||||
|
|
||||||
boot.mode = "efi";
|
boot.mode = "efi";
|
||||||
boot.initrd.availableKernelModules = ["xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" "sdhci_pci" "r8169"];
|
boot.initrd.availableKernelModules = ["xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" "sdhci_pci" "r8169"];
|
||||||
|
|
||||||
|
|
BIN
odroid-h3.png
Normal file
BIN
odroid-h3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 575 KiB |
|
@ -5,10 +5,17 @@
|
||||||
}: let
|
}: let
|
||||||
inherit
|
inherit
|
||||||
(lib)
|
(lib)
|
||||||
|
attrNames
|
||||||
|
concatLines
|
||||||
concatStringsSep
|
concatStringsSep
|
||||||
|
flatten
|
||||||
|
flip
|
||||||
|
mapAttrsToList
|
||||||
mkDefault
|
mkDefault
|
||||||
mkEnableOption
|
mkEnableOption
|
||||||
mkIf
|
mkIf
|
||||||
|
optional
|
||||||
|
replaceStrings
|
||||||
;
|
;
|
||||||
in {
|
in {
|
||||||
options.topology.extractors.services.enable = mkEnableOption "topology service extractor" // {default = true;};
|
options.topology.extractors.services.enable = mkEnableOption "topology service extractor" // {default = true;};
|
||||||
|
@ -42,6 +49,22 @@ in {
|
||||||
nginx = mkIf config.services.nginx.enable {
|
nginx = mkIf config.services.nginx.enable {
|
||||||
name = "NGINX";
|
name = "NGINX";
|
||||||
icon = "services.nginx";
|
icon = "services.nginx";
|
||||||
|
details.reverse = let
|
||||||
|
lines = flatten (flip mapAttrsToList config.services.nginx.virtualHosts (
|
||||||
|
server: vh:
|
||||||
|
flip mapAttrsToList vh.locations (
|
||||||
|
path: location: let
|
||||||
|
upstreamName = replaceStrings ["http://" "https://"] ["" ""] location.proxyPass;
|
||||||
|
passTo =
|
||||||
|
if config.services.nginx.upstreams ? ${upstreamName}
|
||||||
|
then toString (attrNames config.services.nginx.upstreams.${upstreamName}.servers)
|
||||||
|
else location.proxyPass;
|
||||||
|
in
|
||||||
|
optional (path == "/" && location.proxyPass != null) "${server} -> ${passTo}"
|
||||||
|
)
|
||||||
|
));
|
||||||
|
in
|
||||||
|
mkIf (lines != []) {text = concatLines lines;};
|
||||||
};
|
};
|
||||||
|
|
||||||
radicale = mkIf config.services.radicale.enable {
|
radicale = mkIf config.services.radicale.enable {
|
||||||
|
@ -57,6 +80,7 @@ in {
|
||||||
oauth2_proxy = mkIf config.services.oauth2_proxy.enable {
|
oauth2_proxy = mkIf config.services.oauth2_proxy.enable {
|
||||||
name = "OAuth2 Proxy";
|
name = "OAuth2 Proxy";
|
||||||
icon = "services.oauth2-proxy";
|
icon = "services.oauth2-proxy";
|
||||||
|
info = config.services.oauth2_proxy.httpAddress;
|
||||||
};
|
};
|
||||||
|
|
||||||
openssh = mkIf config.services.openssh.enable {
|
openssh = mkIf config.services.openssh.enable {
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
{
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
} @ args: let
|
|
||||||
inherit
|
|
||||||
(lib)
|
|
||||||
mkOption
|
|
||||||
types
|
|
||||||
;
|
|
||||||
in {
|
|
||||||
options.renderers.d2 = {
|
|
||||||
output = mkOption {
|
|
||||||
description = "The derivation containing the rendered output";
|
|
||||||
type = types.path;
|
|
||||||
readOnly = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config.renderers.d2.output = pkgs.runCommand "topology-d2" {} ''
|
|
||||||
mkdir -p $out
|
|
||||||
# cp ${import ./network.nix args} $out/network.d2
|
|
||||||
ln -s ${import ./network.nix args} $out/svgs
|
|
||||||
'';
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
{
|
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}: let
|
|
||||||
inherit
|
|
||||||
(lib)
|
|
||||||
any
|
|
||||||
attrValues
|
|
||||||
concatLines
|
|
||||||
flip
|
|
||||||
optionalString
|
|
||||||
;
|
|
||||||
|
|
||||||
netToD2 = net: ''
|
|
||||||
net_${net.id}: ${net.name} {
|
|
||||||
info: |md
|
|
||||||
${net.cidrv4}
|
|
||||||
${net.cidrv6}
|
|
||||||
|
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
|
|
||||||
nodeInterfaceToD2 = node: interface:
|
|
||||||
concatLines (flip map interface.physicalConnections (x:
|
|
||||||
optionalString (
|
|
||||||
(!any (y: y.node == node.id && y.interface == interface.id) config.nodes.${x.node}.interfaces.${x.interface}.physicalConnections)
|
|
||||||
|| (node.id < x.node)
|
|
||||||
)
|
|
||||||
''
|
|
||||||
node_${node.id} -- node_${x.node}: "" {
|
|
||||||
source-arrowhead.label: ${interface.id}
|
|
||||||
target-arrowhead.label: ${x.interface}
|
|
||||||
}
|
|
||||||
''));
|
|
||||||
|
|
||||||
nodeToD2 = node: ''
|
|
||||||
node_${node.id}: "" {
|
|
||||||
shape: image
|
|
||||||
width: 680
|
|
||||||
icon: ${config.lib.renderers.svg.node.mkPreferredRender node}
|
|
||||||
}
|
|
||||||
|
|
||||||
${concatLines (map (nodeInterfaceToD2 node) (attrValues node.interfaces))}
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
pkgs.writeText "network.d2" ''
|
|
||||||
${concatLines (map netToD2 (attrValues config.networks))}
|
|
||||||
${concatLines (map nodeToD2 (attrValues config.nodes))}
|
|
||||||
''
|
|
|
@ -19,9 +19,10 @@
|
||||||
mapAttrsToList
|
mapAttrsToList
|
||||||
mkOption
|
mkOption
|
||||||
optional
|
optional
|
||||||
optionals
|
|
||||||
optionalAttrs
|
optionalAttrs
|
||||||
|
optionals
|
||||||
recursiveUpdate
|
recursiveUpdate
|
||||||
|
stringLength
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -71,16 +72,15 @@
|
||||||
(optionalAttrs (node.preferredRenderType == "card") {
|
(optionalAttrs (node.preferredRenderType == "card") {
|
||||||
children."node:${node.id}".ports."interface:${interface.id}" = {
|
children."node:${node.id}".ports."interface:${interface.id}" = {
|
||||||
properties."port.side" = "WEST";
|
properties."port.side" = "WEST";
|
||||||
#x = 0;
|
|
||||||
#y = 82 + 42 * lib.lists.findFirstIndex (x: x == interface.id) 0 (builtins.attrNames node.interfaces); # FIXME: just pass index along in function call
|
|
||||||
width = 8;
|
width = 8;
|
||||||
height = 8;
|
height = 8;
|
||||||
# TODO: FIXME: not shown currently in svg
|
style.stroke = "#70a5eb";
|
||||||
# labels.name = {
|
style.fill = "#74bee9";
|
||||||
# text = interface.id;
|
labels.name = {
|
||||||
# width = 33.0;
|
height = 12;
|
||||||
# height = 15.0;
|
width = 7.5 * (stringLength interface.id);
|
||||||
# };
|
text = interface.id;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
@ -104,6 +104,7 @@
|
||||||
scale = 0.8;
|
scale = 0.8;
|
||||||
};
|
};
|
||||||
properties."portConstraints" = "FIXED_SIDE";
|
properties."portConstraints" = "FIXED_SIDE";
|
||||||
|
properties."portLabels.placement" = "OUTSIDE";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -112,6 +113,8 @@
|
||||||
properties."port.side" = "EAST";
|
properties."port.side" = "EAST";
|
||||||
width = 8;
|
width = 8;
|
||||||
height = 8;
|
height = 8;
|
||||||
|
style.stroke = "#49d18d";
|
||||||
|
style.fill = "#78dba9";
|
||||||
};
|
};
|
||||||
edges."node:${node.parent}.ports.guests-to-node:${node.id}" = {
|
edges."node:${node.parent}.ports.guests-to-node:${node.id}" = {
|
||||||
sources = ["children.node:${node.parent}.ports.guests"];
|
sources = ["children.node:${node.parent}.ports.guests"];
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
# TODO:
|
# TODO:
|
||||||
|
# - ip labels on edges
|
||||||
|
# - network centric view
|
||||||
|
# - better layout for interfaces in svg
|
||||||
|
# - sevice infos
|
||||||
# - disks (from disko) + render
|
# - disks (from disko) + render
|
||||||
# - hardware info (image small top and image big bottom and full (no card), maybe just image and render position)
|
# - hardware info (image small top and image big bottom and full (no card), maybe just image and render position)
|
||||||
# - render router and other devices (card with interfaces, card with just image)
|
|
||||||
# - render nodes with guests, guests in short form
|
|
||||||
# - nginx proxy pass render, with upstream support
|
|
||||||
# - more service info
|
# - more service info
|
||||||
# - impermanence render?
|
# - impermanence render?
|
||||||
|
# - nixos nftables firewall render?
|
||||||
# - stable pseudorandom colors from palette with no-reuse until necessary
|
# - stable pseudorandom colors from palette with no-reuse until necessary
|
||||||
# - search todo and do
|
# - search todo and do
|
||||||
# - podman / docker harvesting
|
# - podman / docker harvesting
|
||||||
# - adjust device icon based on guest type
|
|
||||||
# - nixos-container extractor
|
# - nixos-container extractor
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
|
@ -310,6 +311,7 @@ in {
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
lib.renderers.svg = {
|
lib.renderers.svg = {
|
||||||
|
# FIXME: networks.mkOverview = renderHtmlToSvg html.networks.mkOverview "networks-overview";
|
||||||
services.mkOverview = renderHtmlToSvg html.services.mkOverview "services-overview";
|
services.mkOverview = renderHtmlToSvg html.services.mkOverview "services-overview";
|
||||||
|
|
||||||
node = {
|
node = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue