From a1233647776388a22c409f4fb7cf674388a6759e Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Sat, 16 Dec 2023 16:52:38 +0100 Subject: [PATCH] Automatically generated `hosts` file for Wireguard VPN --- modules/wireguard-common/default.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/wireguard-common/default.nix b/modules/wireguard-common/default.nix index eb6eec9..9ebfc78 100644 --- a/modules/wireguard-common/default.nix +++ b/modules/wireguard-common/default.nix @@ -1,4 +1,9 @@ -{config, ...}: { +{ + lib, + config, + vpn, + ... +}: { networking.firewall.interfaces.wg0 = { allowedUDPPortRanges = [ { @@ -18,4 +23,12 @@ privateKeyFile = config.age.secrets."${config.networking.hostName}-wireguard-private-key".path; listenPort = 51820; }; + + networking.hosts = + lib.mapAttrs' + (hostname: vpnConfig: { + name = vpnConfig.ip; + value = ["${hostname}.fleet"]; + }) + vpn; }