about summary refs log tree commit diff
path: root/modules/wireguard.nix
diff options
context:
space:
mode:
authorAzat Bahawi <azat@bahawi.net>2024-05-02 03:17:48 +0300
committerAzat Bahawi <azat@bahawi.net>2024-05-02 03:17:48 +0300
commit9b3ebd974bde5c8ebe1f8c8f049f7ee2c6462655 (patch)
tree408194f6f761872df938888ebc4ce46244168618 /modules/wireguard.nix
parent2024-05-01 (diff)
2024-05-02
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