about summary refs log tree commit diff
path: root/modules/wireguard.nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/wireguard.nix23
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/wireguard.nix b/modules/wireguard.nix
index f645a90..6e5bdbc 100644
--- a/modules/wireguard.nix
+++ b/modules/wireguard.nix
@@ -9,6 +9,7 @@
 with lib;
 let
   cfg = config.nixfiles.modules.wireguard;
+  inherit (config.lib.topology) mkConnection;
 in
 {
   options.nixfiles.modules.wireguard = {
@@ -112,6 +113,13 @@ in
         secrets."wireguard-private-key-${this.hostname}".file = "${inputs.self}/secrets/wireguard-private-key-${this.hostname}";
 
         networking.firewall.trustedInterfaces = [ cfg.interface ];
+
+        topology = with cfg; {
+          nodes.${this.hostname}.interfaces.${interface} = {
+            network = interface;
+            icon = "interfaces.wireguard";
+          };
+        };
       })
       (mkIf cfg.client.enable {
         networking.wg-quick.interfaces.${cfg.interface} = mkMerge [
@@ -210,6 +218,21 @@ in
           withRemoteIp = true;
           port = 9586;
         };
+
+        topology = with cfg; {
+          networks = {
+            ${interface} = {
+              name = interface;
+              cidrv4 = ipv4.subnet;
+              cidrv6 = ipv6.subnet;
+              icon = "interfaces.wireguard";
+            };
+          };
+
+          nodes.${this.hostname}.interfaces.${interface}.physicalConnections = mapAttrsToList (
+            name: _: (mkConnection name interface)
+          ) (filterAttrs (n: v: !v.isOther && n != this.hostname && hasAttr "wireguard" v) my.configurations);
+        };
       })
     ];
 }

Consider giving Nix/NixOS a try! <3