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

71 lines
2 KiB
Nix
Raw Normal View History

2024-06-03 20:49:32 +02:00
{ pkgs, config, factsGenerator, ... }:
2024-06-05 12:51:38 +02:00
let
publicKey = machine: (builtins.readFile "${config.clanCore.clanDir}/machines/${machine}/facts/wireguard.wg0.pub");
in
2023-12-09 17:15:50 +01:00
{
networking.firewall.allowedUDPPorts = [ 51820 ];
clanCore.facts.services.wireguard = factsGenerator.wireguard { name = "wg0"; };
2023-12-09 17:15:50 +01:00
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.clanCore.facts.services.wireguard.secret."wireguard.wg0.key".path;
2023-12-09 17:15:50 +01:00
mtu = 1280;
postUp = ''
${pkgs.iptables}/bin/iptables -A FORWARD -i wg0 -j ACCEPT
'';
postDown = ''
${pkgs.iptables}/bin/iptables -D FORWARD -i wg0 -j ACCEPT
'';
peers = [
2024-06-06 10:35:20 +02:00
# server
# ------
# start at 1
2023-12-09 17:15:50 +01:00
{
# chungus
2024-06-05 12:51:38 +02:00
publicKey = publicKey "chungus";
2023-12-09 17:15:50 +01:00
allowedIPs = [ "10.100.0.2/32" ];
}
2024-06-06 10:35:20 +02:00
# desktops
# --------
# start at 10
2023-12-09 17:15:50 +01:00
{
# cream
2024-06-05 12:51:38 +02:00
publicKey = publicKey "cream";
2024-06-06 10:35:20 +02:00
allowedIPs = [ "10.100.0.6/32" ]; # todo : change ip
2023-12-09 17:15:50 +01:00
}
2024-04-12 19:55:08 +02:00
{
# cherry
2024-06-05 12:51:38 +02:00
publicKey = publicKey "cherry";
2024-06-06 10:35:20 +02:00
allowedIPs = [ "10.100.0.7/32" ]; # todo : change ip
2024-04-12 19:55:08 +02:00
}
2024-06-06 10:35:20 +02:00
# mobild devices
# --------------
# start at 100
2024-06-06 10:31:44 +02:00
{
# iphone palo
publicKey = "ICeZLWYzF+nTffMV0+8yfW1WJsUQNhNbKQ4rRbn5hDs=";
allowedIPs = [ "10.100.0.101/32" ];
}
2024-05-11 15:46:59 +02:00
{
2024-06-06 10:31:44 +02:00
# ipad palo
publicKey = "wN81/4K2d5tcxqrxnjOpKw9YpAkPdp0/8cCN1B7icVo=";
allowedIPs = [ "10.100.0.102/32" ];
2024-05-11 15:46:59 +02:00
}
{
2024-06-06 10:31:44 +02:00
# iphone tina
publicKey = "8f8fYGymH3Tq8d14B2+ijMiHwocEbUIXSZji3U29IhA=";
allowedIPs = [ "10.100.0.103/32" ];
2024-05-11 15:46:59 +02:00
}
2023-12-09 17:15:50 +01:00
];
};
};
}