From f37c491f8e2eff368c9630ef00d5d3762719c352 Mon Sep 17 00:00:00 2001 From: oddlama Date: Tue, 19 Mar 2024 03:46:45 +0100 Subject: [PATCH] feat(topology): add more services --- hosts/kroma/default.nix | 4 ++ topology/icons/devices/desktop.svg | 1 + topology/icons/devices/ethernet.svg | 57 --------------------- topology/icons/devices/laptop.svg | 1 + topology/icons/devices/nixos.svg | 48 +++++++++++++++++ topology/icons/services/adguardhome.svg | 1 + topology/icons/services/forgejo.svg | 1 + topology/icons/services/grafana.svg | 1 + topology/icons/services/kanidm.svg | 1 + topology/icons/services/loki.svg | 1 + topology/icons/services/nginx.svg | 1 + topology/icons/services/oauth2-proxy.svg | 1 + topology/icons/services/radicale.svg | 1 + topology/icons/services/samba.svg | 1 + topology/nixos/extractors/services.nix | 45 ++++++++++++++++ topology/options/nodes.nix | 5 +- topology/topology/renderers/d2/network.nix | 1 + topology/topology/renderers/svg/default.nix | 7 ++- 18 files changed, 118 insertions(+), 60 deletions(-) create mode 100644 topology/icons/devices/desktop.svg delete mode 100644 topology/icons/devices/ethernet.svg create mode 100644 topology/icons/devices/laptop.svg create mode 100644 topology/icons/devices/nixos.svg create mode 100644 topology/icons/services/adguardhome.svg create mode 100644 topology/icons/services/forgejo.svg create mode 100644 topology/icons/services/grafana.svg create mode 100644 topology/icons/services/kanidm.svg create mode 100644 topology/icons/services/loki.svg create mode 100644 topology/icons/services/nginx.svg create mode 100644 topology/icons/services/oauth2-proxy.svg create mode 100644 topology/icons/services/radicale.svg create mode 100644 topology/icons/services/samba.svg diff --git a/hosts/kroma/default.nix b/hosts/kroma/default.nix index bfc184c..95c1f44 100644 --- a/hosts/kroma/default.nix +++ b/hosts/kroma/default.nix @@ -77,4 +77,8 @@ nixpkgs.config.permittedInsecurePackages = lib.trace "please remove insecure nix 2.16.2 very fast ok thx bye" [ "nix-2.16.2" ]; + + topology.self.icon = "devices.desktop"; + #topology.self.interfaces.lan1.connections = [{ id = "dumbswitch"; interface = "lan1"; }]; + #topology.nodes.dumbswitch = lib.topology.mkSwitch "Dummer Switch"; } diff --git a/topology/icons/devices/desktop.svg b/topology/icons/devices/desktop.svg new file mode 100644 index 0000000..6ad3e3d --- /dev/null +++ b/topology/icons/devices/desktop.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/icons/devices/ethernet.svg b/topology/icons/devices/ethernet.svg deleted file mode 100644 index 1d8045a..0000000 --- a/topology/icons/devices/ethernet.svg +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/topology/icons/devices/laptop.svg b/topology/icons/devices/laptop.svg new file mode 100644 index 0000000..2ea6714 --- /dev/null +++ b/topology/icons/devices/laptop.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/icons/devices/nixos.svg b/topology/icons/devices/nixos.svg new file mode 100644 index 0000000..443f9d8 --- /dev/null +++ b/topology/icons/devices/nixos.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/topology/icons/services/adguardhome.svg b/topology/icons/services/adguardhome.svg new file mode 100644 index 0000000..0d9b102 --- /dev/null +++ b/topology/icons/services/adguardhome.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/icons/services/forgejo.svg b/topology/icons/services/forgejo.svg new file mode 100644 index 0000000..b856343 --- /dev/null +++ b/topology/icons/services/forgejo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/icons/services/grafana.svg b/topology/icons/services/grafana.svg new file mode 100644 index 0000000..0cb40a9 --- /dev/null +++ b/topology/icons/services/grafana.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/icons/services/kanidm.svg b/topology/icons/services/kanidm.svg new file mode 100644 index 0000000..acd77ec --- /dev/null +++ b/topology/icons/services/kanidm.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/icons/services/loki.svg b/topology/icons/services/loki.svg new file mode 100644 index 0000000..5ba43ce --- /dev/null +++ b/topology/icons/services/loki.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/icons/services/nginx.svg b/topology/icons/services/nginx.svg new file mode 100644 index 0000000..8d95e4b --- /dev/null +++ b/topology/icons/services/nginx.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/icons/services/oauth2-proxy.svg b/topology/icons/services/oauth2-proxy.svg new file mode 100644 index 0000000..b269949 --- /dev/null +++ b/topology/icons/services/oauth2-proxy.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/icons/services/radicale.svg b/topology/icons/services/radicale.svg new file mode 100644 index 0000000..531ecde --- /dev/null +++ b/topology/icons/services/radicale.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/icons/services/samba.svg b/topology/icons/services/samba.svg new file mode 100644 index 0000000..2b663ce --- /dev/null +++ b/topology/icons/services/samba.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/topology/nixos/extractors/services.nix b/topology/nixos/extractors/services.nix index bccd744..fde5e69 100644 --- a/topology/nixos/extractors/services.nix +++ b/topology/nixos/extractors/services.nix @@ -11,6 +11,51 @@ ; in { topology.self.services = { + adguardhome = mkIf config.services.adguardhome.enable { + name = "AdGuard Home"; + icon = "services.adguardhome"; + }; + + forgejo = mkIf config.services.forgejo.enable { + name = "Forgejo"; + icon = "services.forgejo"; + }; + + grafana = mkIf config.services.grafana.enable { + name = "Grafana"; + icon = "services.grafana"; + }; + + kanidm = mkIf config.services.kanidm.enableServer { + name = "Kanidm"; + icon = "services.kanidm"; + }; + + loki = mkIf config.services.loki.enable { + name = "Loki"; + icon = "services.loki"; + }; + + nginx = mkIf config.services.nginx.enable { + name = "NGINX"; + icon = "services.nginx"; + }; + + radicale = mkIf config.services.radicale.enable { + name = "Radicale"; + icon = "services.radicale"; + }; + + samba = mkIf config.services.samba.enable { + name = "Samba"; + icon = "services.samba"; + }; + + oauth2_proxy = mkIf config.services.oauth2_proxy.enable { + name = "OAuth2 Proxy"; + icon = "services.oauth2-proxy"; + }; + openssh = mkIf config.services.openssh.enable { hidden = mkDefault true; # Causes a lot of much clutter name = "OpenSSH"; diff --git a/topology/options/nodes.nix b/topology/options/nodes.nix index 4a34ea7..e733743 100644 --- a/topology/options/nodes.nix +++ b/topology/options/nodes.nix @@ -48,7 +48,6 @@ in # FIXME: TODO hardware description "Odroid H3" # FIXME: TODO hardware image - # FIXME: TODO are these good types? how about nixos vs router vs ... deviceType = mkOption { description = "TODO"; type = types.enum ["nixos" "microvm" "nixos-container"]; @@ -70,7 +69,7 @@ in config = { # Set the default icon, if an icon exists with a matching name deviceIcon = mkIf (config.topology.isMainModule && config.icons.devices ? ${nodeSubmod.config.deviceType}) ( - mkDefault ("interfaces." + nodeSubmod.config.deviceType) + mkDefault ("devices." + nodeSubmod.config.deviceType) ); }; })); @@ -80,6 +79,8 @@ in assertions = flatten ( flip map (attrValues config.nodes) ( node: [ + (config.lib.assertions.iconValid + node.icon "nodes.${node.id}.icon") (config.lib.assertions.iconValid node.deviceIcon "nodes.${node.id}.deviceIcon") ] diff --git a/topology/topology/renderers/d2/network.nix b/topology/topology/renderers/d2/network.nix index 1e406a2..c038dea 100644 --- a/topology/topology/renderers/d2/network.nix +++ b/topology/topology/renderers/d2/network.nix @@ -8,6 +8,7 @@ (lib) attrValues concatLines + optionalString ; netToD2 = net: '' diff --git a/topology/topology/renderers/svg/default.nix b/topology/topology/renderers/svg/default.nix index 34921ea..6c2567f 100644 --- a/topology/topology/renderers/svg/default.nix +++ b/topology/topology/renderers/svg/default.nix @@ -52,6 +52,8 @@ '' else builtins.throw "Unsupported icon file type: ${file}"; + mkImageMaybe = twAttrs: file: optionalString (file != null) (mkImage twAttrs file); + mkSpacer = name: /* html @@ -150,10 +152,12 @@ html */ '' -
+
+ ${mkImageMaybe "w-12 h-12 mr-3" (config.lib.icons.get node.icon)}

${node.name}

${node.deviceType}

+ ${mkImageMaybe "w-16 h-16 ml-3" (config.lib.icons.get node.deviceIcon)}
''; @@ -182,6 +186,7 @@ ${optionalString (services != []) (mkSpacer "Services")} ${concatLines (map mkService services)} + ${optionalString (services != []) spacingMt2}
'';