blob: 76586ba68967728d32c0c070d4d6dc682faffcdd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
{
config,
lib,
hostConfigurations,
...
}:
let
wgHosts = {
bree = {
ip = 40;
publicKey = hostConfigurations.bree.wgPublicKey;
endpoint = "192.168.1.50";
};
argonath = {
ip = 51;
publicKey = hostConfigurations.argonath.wgPublicKey;
endpoint = "157.230.146.234";
};
rivendell = {
ip = 60;
publicKey = hostConfigurations.rivendell.wgPublicKey;
endpoint = "192.168.1.114";
};
};
wgPort = 51820;
wgSubnet = "10.100.0";
currentHostname = config.networking.hostName;
currentHost =
wgHosts.${currentHostname}
or (throw "Host ${currentHostname} not found in wireguard configuration");
peers = lib.mapAttrsToList (
_hostname: hostCfg:
{
publicKey = hostCfg.publicKey;
allowedIPs = [ "${wgSubnet}.${toString hostCfg.ip}/32" ];
persistentKeepalive = 25;
}
// lib.optionalAttrs (hostCfg.endpoint != null) {
endpoint = "${hostCfg.endpoint}:${toString wgPort}";
}
) (lib.filterAttrs (n: _v: n != currentHostname) wgHosts);
in
{
networking.wireguard = {
enable = true;
interfaces.wg0 = {
ips = [ "${wgSubnet}.${toString currentHost.ip}/32" ];
listenPort = wgPort;
privateKeyFile = config.age.secrets.wireguard.path;
inherit peers;
};
};
networking.firewall.trustedInterfaces = [ "wg0" ];
networking.firewall.allowedUDPPorts = [ wgPort ];
}
|