mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-10 14:50:40 +02:00
feat(topology): extract more service info and add helper functions to define stuff
This commit is contained in:
parent
cc35dd599a
commit
30579a433e
12 changed files with 174 additions and 175 deletions
1
topology/icons/devices/cloud.svg
Normal file
1
topology/icons/devices/cloud.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="400" aria-hidden="true" class="iconify iconify--noto" viewBox="0 0 128 128"><path fill="#e4eaee" d="M23.45 62.3c.72-.72-1.27-9.29 7.6-15.91s14.92-2.67 15.77-2.96c.84-.28 4.79-17.6 21.4-22.1s33.93 3.94 38.01 18.02c3.73 12.87.84 21.54 1.27 22.1.42.56 8.45.28 13.09 7.74s2.96 12.11 2.96 12.11l-29.56 9.15h-47.3S5.02 79.47 4.6 77.5s.53-8.37 7.32-12.25c5.9-3.37 10.26-1.68 11.53-2.95"/><path fill="#bacdd2" d="M35.16 92.84s-15.78 3.3-26.45-4.96C2.29 82.9 4.63 74.83 4.63 74.83s4.6 4.65 13.89 5.91c9.29 1.27 19.71.84 19.71.84s2.6 4.44 12.39 6.48c12.27 2.55 18.74-3.73 18.74-3.73s3.36 4.02 15.19 4.3 18.46-7.98 19.57-8.17c.56-.09 3.82 2.87 10.28 1.83 6.15-.99 9.39-3.66 9.39-3.66s.89 6.62-5.3 10.7c-4.83 3.18-13.23 3.52-13.23 3.52s-1.28 4.91-7.05 8.48c-5.36 3.33-14.6 4.44-21.44 2.4-8.59-2.56-10.72-6.47-10.72-6.47s-6.4 3.75-16.4 2.48c-9.45-1.18-14.49-6.9-14.49-6.9"/></svg>
|
After Width: | Height: | Size: 929 B |
|
@ -21,30 +21,57 @@ in {
|
|||
options.topology.extractors.services.enable = mkEnableOption "topology service extractor" // {default = true;};
|
||||
|
||||
config.topology.self.services = mkIf config.topology.extractors.services.enable {
|
||||
adguardhome = mkIf config.services.adguardhome.enable {
|
||||
name = "AdGuard Home";
|
||||
icon = "services.adguardhome";
|
||||
};
|
||||
adguardhome = let
|
||||
address = config.services.adguardhome.settings.bind_host or null;
|
||||
port = config.services.adguardhome.settings.bind_port or null;
|
||||
in
|
||||
mkIf config.services.adguardhome.enable {
|
||||
name = "AdGuard Home";
|
||||
icon = "services.adguardhome";
|
||||
details.listen = mkIf (address != null && port != null) {text = "${address}:${toString port}";};
|
||||
};
|
||||
|
||||
forgejo = mkIf config.services.forgejo.enable {
|
||||
name = "Forgejo";
|
||||
icon = "services.forgejo";
|
||||
};
|
||||
forgejo = let
|
||||
address = config.services.forgejo.settings.server.HTTP_ADDR or null;
|
||||
port = config.services.forgejo.settings.server.HTTP_PORT or null;
|
||||
in
|
||||
mkIf config.services.forgejo.enable {
|
||||
name =
|
||||
if config.services.forgejo.settings ? DEFAULT.APP_NAME
|
||||
then "Forgejo (${config.services.forgejo.settings.DEFAULT.APP_NAME})"
|
||||
else "Forgejo";
|
||||
icon = "services.forgejo";
|
||||
info = mkIf (config.services.forgejo.settings ? server.ROOT_URL) config.services.forgejo.settings.server.ROOT_URL;
|
||||
details.listen = mkIf (address != null && port != null) {text = "${address}:${toString port}";};
|
||||
};
|
||||
|
||||
grafana = mkIf config.services.grafana.enable {
|
||||
name = "Grafana";
|
||||
icon = "services.grafana";
|
||||
};
|
||||
grafana = let
|
||||
address = config.services.grafana.settings.server.http_addr or null;
|
||||
port = config.services.grafana.settings.server.http_port or null;
|
||||
in
|
||||
mkIf config.services.grafana.enable {
|
||||
name = "Grafana";
|
||||
icon = "services.grafana";
|
||||
info = config.services.grafana.settings.server.root_url;
|
||||
details.listen = mkIf (address != null && port != null) {text = "${address}:${toString port}";};
|
||||
};
|
||||
|
||||
kanidm = mkIf config.services.kanidm.enableServer {
|
||||
name = "Kanidm";
|
||||
icon = "services.kanidm";
|
||||
info = config.services.kanidm.serverSettings.origin;
|
||||
details.listen.text = config.services.kanidm.serverSettings.bindaddress;
|
||||
};
|
||||
|
||||
loki = mkIf config.services.loki.enable {
|
||||
name = "Loki";
|
||||
icon = "services.loki";
|
||||
};
|
||||
loki = let
|
||||
address = config.services.loki.configuration.server.http_listen_address or null;
|
||||
port = config.services.loki.configuration.server.http_listen_port or null;
|
||||
in
|
||||
mkIf config.services.loki.enable {
|
||||
name = "Loki";
|
||||
icon = "services.loki";
|
||||
details.listen = mkIf (address != null && port != null) {text = "${address}:${toString port}";};
|
||||
};
|
||||
|
||||
nginx = mkIf config.services.nginx.enable {
|
||||
name = "NGINX";
|
||||
|
@ -70,6 +97,7 @@ in {
|
|||
radicale = mkIf config.services.radicale.enable {
|
||||
name = "Radicale";
|
||||
icon = "services.radicale";
|
||||
details.listen = mkIf (config.services.radicale.settings ? server.hosts) {text = toString config.services.radicale.settings.server.hosts;};
|
||||
};
|
||||
|
||||
samba = mkIf config.services.samba.enable {
|
||||
|
|
|
@ -327,6 +327,11 @@ in
|
|||
icon = mkIf (config.topology.isMainModule && config.icons.interfaces ? ${submod.config.type}) (
|
||||
mkDefault ("interfaces." + submod.config.type)
|
||||
);
|
||||
|
||||
# For switches: Share the network with any other interface by default
|
||||
sharesNetworkWith = mkIf (config.topology.isMainModule && nodeSubmod.config.deviceType == "switch") (
|
||||
mkDefault (const true)
|
||||
);
|
||||
};
|
||||
}));
|
||||
};
|
||||
|
@ -335,9 +340,6 @@ in
|
|||
};
|
||||
|
||||
config = {
|
||||
lib.a.a = connections;
|
||||
lib.a.b = networkDefiningInterfaces;
|
||||
lib.a.c = propagatedNetworks;
|
||||
assertions = flatten (flip map (attrValues config.nodes) (
|
||||
node:
|
||||
flip map (attrValues node.interfaces) (
|
||||
|
|
|
@ -6,14 +6,17 @@ f: {
|
|||
inherit
|
||||
(lib)
|
||||
attrValues
|
||||
concatMap
|
||||
elem
|
||||
flatten
|
||||
flip
|
||||
literalExpression
|
||||
mapAttrsToList
|
||||
mkDefault
|
||||
mkIf
|
||||
mkMerge
|
||||
mkOption
|
||||
toList
|
||||
types
|
||||
;
|
||||
in
|
||||
|
@ -125,6 +128,56 @@ in
|
|||
};
|
||||
|
||||
config = {
|
||||
lib.helpers = rec {
|
||||
# Finally we found it, the one-and-only true cloud.
|
||||
mkInternet = {connections ? [], ...}: {
|
||||
name = "Internet";
|
||||
deviceType = "internet";
|
||||
hardware.image = ../icons/devices/cloud.svg;
|
||||
interfaces."*".physicalConnections = toList connections;
|
||||
};
|
||||
|
||||
mkConnection = node: interface: {inherit node interface;};
|
||||
mkConnectionRev = node: interface: {
|
||||
inherit node interface;
|
||||
renderer.reverse = true;
|
||||
};
|
||||
|
||||
mkSwitch = name: {
|
||||
info ? null,
|
||||
image ? null,
|
||||
interfaceGroups ? [],
|
||||
connections ? {},
|
||||
...
|
||||
}: {
|
||||
inherit name;
|
||||
deviceType = "switch";
|
||||
hardware = {
|
||||
info = mkIf (info != null) info;
|
||||
image = mkIf (image != null) image;
|
||||
};
|
||||
interfaces = mkMerge (
|
||||
flip mapAttrsToList connections (interface: conns: {
|
||||
${interface}.physicalConnections = toList conns;
|
||||
})
|
||||
++ flip concatMap interfaceGroups (
|
||||
group:
|
||||
flip map group (
|
||||
interface: {
|
||||
${interface}.sharesNetworkWith = x: elem x group;
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
mkRouter = name: args:
|
||||
mkSwitch name args
|
||||
// {
|
||||
deviceType = "router";
|
||||
};
|
||||
};
|
||||
|
||||
assertions = flatten (
|
||||
flip map (attrValues config.nodes) (
|
||||
node: [
|
||||
|
|
|
@ -205,7 +205,7 @@
|
|||
"portLabels.placement" = "OUTSIDE";
|
||||
}
|
||||
// optionalAttrs (node.renderer.preferredType == "card") {
|
||||
"portConstraints" = "FIXED_SIDE";
|
||||
# "portConstraints" = "FIXED_SIDE";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# TODO:
|
||||
# - macvtap interface type svg with small link
|
||||
# - address port label render make newline capable (multiple port labels)
|
||||
# - NAT indication
|
||||
# - embed font globally, try removing satori embed?
|
||||
|
@ -115,9 +116,9 @@
|
|||
else net.style.secondaryColor;
|
||||
in
|
||||
{
|
||||
solid = ''<div tw="flex flex-none ${twAttrs} bg-[${net.style.primaryColor}] rounded-md"></div>'';
|
||||
dashed = ''<div tw="flex flex-none ${twAttrs} rounded-md" style="backgroundImage: linear-gradient(90deg, ${net.style.primaryColor} 0%, ${net.style.primaryColor} 50%, ${secondaryColor} 50.01%, ${secondaryColor} 100%);"></div>'';
|
||||
dotted = ''<div tw="flex flex-none ${twAttrs} rounded-md" style="backgroundImage: radial-gradient(circle, ${net.style.primaryColor} 30%, ${secondaryColor} 30.01%);"></div>'';
|
||||
solid = ''<div tw="flex flex-none ${twAttrs} bg-[${net.style.primaryColor}]"></div>'';
|
||||
dashed = ''<div tw="flex flex-none ${twAttrs}" style="backgroundImage: linear-gradient(90deg, ${net.style.primaryColor} 0%, ${net.style.primaryColor} 50%, ${secondaryColor} 50.01%, ${secondaryColor} 100%);"></div>'';
|
||||
dotted = ''<div tw="flex flex-none ${twAttrs}" style="backgroundImage: radial-gradient(circle, ${net.style.primaryColor} 30%, ${secondaryColor} 30.01%);"></div>'';
|
||||
}
|
||||
.${net.style.pattern};
|
||||
|
||||
|
@ -130,7 +131,7 @@
|
|||
*/
|
||||
''
|
||||
<div tw="flex flex-row mx-6 mt-2 items-center">
|
||||
${html.net.netStylePreview net "w-8 h-4 mr-4"}
|
||||
${html.net.netStylePreview net "w-12 h-4 mr-4 rounded-md"}
|
||||
<h2 tw="text-2xl font-bold">${net.name}</h2>
|
||||
<div tw="flex grow min-w-8"></div>
|
||||
${mkImageMaybe "w-12 h-12 ml-4" (config.lib.icons.get net.icon)}
|
||||
|
@ -160,12 +161,12 @@
|
|||
*/
|
||||
''
|
||||
<div tw="flex flex-col mx-4 mt-2 rounded-lg p-2">
|
||||
<div tw="flex flex-row items-center">
|
||||
${html.net.netStylePreview net "w-12 h-6 mr-4"}
|
||||
<div tw="flex flex-row">
|
||||
${html.net.netStylePreview net "w-12 h-4 mt-2 mr-4 rounded-md"}
|
||||
<div tw="flex flex-col grow">
|
||||
<h1 tw="text-lg font-bold m-0">${net.name}</h1>
|
||||
${optionalString (net.cidrv4 != null) ''<div tw="flex flex-row"><span tw="text-md m-0"><b>CIDRv4</b></span><span tw="text-md text-[${net.style.primaryColor}] m-0 ml-4">${net.cidrv4}</span></div>''}
|
||||
${optionalString (net.cidrv6 != null) ''<div tw="flex flex-row"><span tw="text-md m-0"><b>CIDRv6</b></span><span tw="text-md text-[${net.style.primaryColor}] m-0 ml-4">${net.cidrv6}</span></div>''}
|
||||
${optionalString (net.cidrv4 != null) ''<div tw="flex flex-row"><span tw="text-md text-[#7a899f] m-0"><b>CIDRv4</b></span><span tw="text-md text-[${net.style.primaryColor}] m-0 ml-4">${net.cidrv4}</span></div>''}
|
||||
${optionalString (net.cidrv6 != null) ''<div tw="flex flex-row"><span tw="text-md text-[#7a899f] m-0"><b>CIDRv6</b></span><span tw="text-md text-[${net.style.primaryColor}] m-0 ml-4">${net.cidrv6}</span></div>''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue