From 694bd7d7123ec4bf3702a5c51f0b7c436e8af02a Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 22 Mar 2023 21:26:02 +0100 Subject: [PATCH] cluster/services/wireguard: use hostLinks --- cluster/services/wireguard/default.nix | 19 +++++++------------ cluster/services/wireguard/mesh.nix | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/cluster/services/wireguard/default.nix b/cluster/services/wireguard/default.nix index 5c343cb..780cf8b 100644 --- a/cluster/services/wireguard/default.nix +++ b/cluster/services/wireguard/default.nix @@ -1,4 +1,4 @@ -{ config, depot, ... }: +{ config, depot, lib, ... }: let inherit (depot.config) hours; @@ -13,16 +13,11 @@ let in { vars = { - mesh = { - checkmate = config.links.mesh-node-checkmate.extra; - thunderskin = config.links.mesh-node-thunderskin.extra; - VEGAS = config.links.mesh-node-VEGAS.extra; - prophet = config.links.mesh-node-prophet.extra; - }; + mesh = lib.genAttrs config.services.wireguard.nodes.mesh (node: config.hostLinks.${node}.mesh.extra); inherit meshNet; }; - links = { - mesh-node-checkmate = { + hostLinks = { + checkmate.mesh = { ipv4 = getExtAddr hours.checkmate; extra = { meshIp = "10.1.1.32"; @@ -32,7 +27,7 @@ in extraRoutes = []; }; }; - mesh-node-thunderskin = { + thunderskin.mesh = { ipv4 = getExtAddr hours.thunderskin; extra = { meshIp = "10.1.1.4"; @@ -42,7 +37,7 @@ in extraRoutes = []; }; }; - mesh-node-VEGAS = { + VEGAS.mesh = { ipv4 = getExtAddr hours.VEGAS; extra = { meshIp = "10.1.1.5"; @@ -52,7 +47,7 @@ in extraRoutes = [ "${hours.VEGAS.interfaces.vstub.addr}/32" "10.10.0.0/16" ]; }; }; - mesh-node-prophet = { + prophet.mesh = { ipv4 = getExtAddr hours.prophet; extra = { meshIp = "10.1.1.9"; diff --git a/cluster/services/wireguard/mesh.nix b/cluster/services/wireguard/mesh.nix index c154968..004a587 100644 --- a/cluster/services/wireguard/mesh.nix +++ b/cluster/services/wireguard/mesh.nix @@ -2,10 +2,10 @@ let inherit (config.networking) hostName; - link = cluster.config.links."mesh-node-${hostName}"; + link = cluster.config.hostLinks.${hostName}.mesh; mkPeer = peerName: let - peerLink = cluster.config.links."mesh-node-${peerName}"; + peerLink = cluster.config.hostLinks.${peerName}.mesh; in { publicKey = peerLink.extra.pubKey; allowedIPs = [ "${peerLink.extra.meshIp}/32" ] ++ peerLink.extra.extraRoutes;