niksos/hosts/chmura/wireguard.nix

40 lines
1,016 B
Nix
Raw Normal View History

2023-07-16 11:21:14 +02:00
{
config,
pkgs,
inputs,
...
}: {
networking.nat = {
enable = true;
externalInterface = "enp6s0";
internalInterfaces = [ "wg0" ];
};
2023-07-20 15:51:48 +02:00
networking.firewall = {
allowedUDPPorts = [ 51820 ];
};
2023-07-16 11:21:14 +02:00
networking.wireguard.interfaces = {
wg0 = {
2023-07-20 15:51:48 +02:00
ips = [ "192.168.15.1/24" ];
2023-07-16 11:21:14 +02:00
listenPort = 51820;
postSetup = ''
2023-07-20 15:51:48 +02:00
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 192.168.15.0/24 -o enp6s0 -j MASQUERADE
2023-07-16 11:21:14 +02:00
'';
postShutdown = ''
2023-07-20 15:51:48 +02:00
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s 192.168.15.0/24 -o enp6s0 -j MASQUERADE
2023-07-16 11:21:14 +02:00
'';
privateKeyFile = "/home/chmura/.wg/private";
peers = [
{
2023-07-20 15:51:48 +02:00
# main laptop
publicKey = "y+bdB0CdX6xm4vK2p2+5vQey9gEDphBf8V/DFt1oaC0=";
2023-07-16 11:21:14 +02:00
allowedIPs = [ "192.168.15.0/24" ];
}
];
};
};
}