nixos-config/nixos/machines/robi/network-wireguard.nix

56 lines
1.6 KiB
Nix
Raw Normal View History

2023-01-19 12:31:04 +01:00
{ pkgs, config, ... }:
{
2023-11-18 12:50:09 +01:00
# networking.firewall.trustedInterfaces = [ "wg0" ];
2023-01-19 12:31:04 +01:00
networking.firewall.allowedUDPPorts = [ 51820 ];
sops.secrets.wireguard_private = { };
boot.kernel.sysctl."net.ipv4.ip_forward" = true;
# Enable WireGuard
networking.wg-quick.interfaces = {
# Hub and Spoke Setup
# https://www.procustodibus.com/blog/2020/11/wireguard-hub-and-spoke-config/
wg0 = {
address = [ "10.100.0.1/32" ];
listenPort = 51820; # to match firewall allowedUDPPorts (without this wg uses random port numbers)
privateKeyFile = config.sops.secrets.wireguard_private.path;
mtu = 1280;
postUp = ''
${pkgs.iptables}/bin/iptables -A FORWARD -i wg0 -j ACCEPT
'';
postDown = ''
${pkgs.iptables}/bin/iptables -D FORWARD -i wg0 -j ACCEPT
'';
# clients
peers = [
{
2023-05-12 11:17:58 +02:00
# chungus
2023-01-19 12:31:04 +01:00
publicKey = "wb54y/fG8ocSH9QrDmfajez/fUcJBZK369xLu37XBHk=";
allowedIPs = [ "10.100.0.2/32" ];
}
{
# sterni
publicKey = "SdMRgC5IM7dywzZxLAHm45cpj9J3IENTMClZm1BxbV4=";
allowedIPs = [ "10.100.0.3/32" ];
}
{
# iphone
publicKey = "XPVzH+wBLsqukTHHjngkGJhYN0nRdQ7esadiimMJQnI=";
allowedIPs = [ "10.100.0.4/32" ];
}
2023-02-02 19:15:25 +01:00
{
# tina
2023-07-09 19:01:19 +02:00
publicKey = "RZsuQfWfAQLMm45ZiuNLBwcpL+GEbPYTRTrASFzMCFQ=";
2023-02-02 19:15:25 +01:00
allowedIPs = [ "10.100.0.5/32" ];
}
2023-02-13 18:40:56 +01:00
{
# cream
publicKey = "R1Vk1DDG/LsVU0HHRDmOJshXOVnNzPVbuv5hP7ZSGEQ=";
allowedIPs = [ "10.100.0.6/32" ];
}
2023-01-19 12:31:04 +01:00
];
};
};
}