blob: 6f51ddfc2c2f73ff130f848e070a4837e74e65ef (
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
|
{
config,
lib,
...
}: let
cfg = config.collinux.wireguard;
in
lib.mkIf cfg.enable {
boot.extraModulePackages = [config.boot.kernelPackages.wireguard];
boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
networking.useNetworkd = true;
systemd.network = {
netdevs."10-wg" = {
netdevConfig = {
Kind = "wireguard";
Name = "wg0";
};
wireguardConfig = {
PrivateKeyFile = cfg.privateKeyFile;
ListenPort = 51820;
};
wireguardPeers =
builtins.map (m: {
PublicKey = m.publicKey;
AllowedIPs = [m.ip];
Endpoint = m.endpoint;
})
cfg.peers;
};
networks."12-wireguard" = {
name = "wg0";
networkConfig = {
Address = cfg.ip;
DHCP = "no";
Gateway = cfg.gateway;
IPMasquerade = "ipv4";
IPv4Forwarding = true;
IPv6AcceptRA = false;
};
};
};
}
|