blob: 9f05e431bdf8f8f8738d4a2c905f552f01e0a267 (
plain)
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
|
{
config,
lib,
...
}: let
cfg = config.collinux.wireguard;
in
lib.mkIf cfg.enable {
networking.firewall.checkReversePath = "loose";
networking.useNetworkd = true;
systemd.network = {
enable = true;
netdevs."10-wg" = {
netdevConfig = {
Kind = "wireguard";
Name = "wg0";
};
wireguardConfig = {
PrivateKeyFile = cfg.privateKeyFile;
ListenPort = 51820;
};
wireguardPeers =
cfg.peers
|> builtins.mapAttrs (_: m:
{
PublicKey = m.publicKey;
AllowedIPs = [m.ip];
PersistentKeepalive = 25;
}
// (lib.optionalAttrs (m.endpoint != null) {
Endpoint = m.endpoint;
}))
|> builtins.attrValues;
};
networks."12-wireguard" = {
name = "wg0";
networkConfig = {
Address = cfg.ip;
DHCP = "no";
Gateway = cfg.gateway;
};
};
};
}
|