63 lines
1.9 KiB
Nix
63 lines
1.9 KiB
Nix
{ pkgs, config, factsGenerator, ... }:
|
|
let
|
|
publicKey = machine: (builtins.readFile "${config.clanCore.clanDir}/machines/${machine}/facts/wireguard.wg0.pub");
|
|
in
|
|
{
|
|
networking.firewall.allowedUDPPorts = [ 51820 ];
|
|
clanCore.facts.services.wireguard = factsGenerator.wireguard { name = "wg0"; };
|
|
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;
|
|
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 = [
|
|
{
|
|
# chungus
|
|
publicKey = publicKey "chungus";
|
|
allowedIPs = [ "10.100.0.2/32" ];
|
|
}
|
|
{
|
|
# cream
|
|
publicKey = publicKey "cream";
|
|
allowedIPs = [ "10.100.0.6/32" ];
|
|
}
|
|
{
|
|
# cherry
|
|
publicKey = publicKey "cherry";
|
|
allowedIPs = [ "10.100.0.7/32" ];
|
|
}
|
|
# mobil devices start with 100
|
|
{
|
|
# iphone palo
|
|
publicKey = "ICeZLWYzF+nTffMV0+8yfW1WJsUQNhNbKQ4rRbn5hDs=";
|
|
allowedIPs = [ "10.100.0.101/32" ];
|
|
}
|
|
{
|
|
# ipad palo
|
|
publicKey = "wN81/4K2d5tcxqrxnjOpKw9YpAkPdp0/8cCN1B7icVo=";
|
|
allowedIPs = [ "10.100.0.102/32" ];
|
|
}
|
|
{
|
|
# iphone tina
|
|
publicKey = "8f8fYGymH3Tq8d14B2+ijMiHwocEbUIXSZji3U29IhA=";
|
|
allowedIPs = [ "10.100.0.103/32" ];
|
|
}
|
|
];
|
|
};
|
|
};
|
|
}
|