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

81 lines
2.3 KiB
Nix
Raw Normal View History

2024-08-29 03:26:04 +02:00
{
pkgs,
config,
factsGenerator,
clanLib,
lib,
...
}:
2024-06-05 12:51:38 +02:00
let
2024-08-29 03:26:04 +02:00
otherMachines = lib.filterAttrs (name: _value: name != "orbi") (
clanLib.readFactsFromAllMachines [
"wireguard.wg0.pub"
"wireguard.wg0.cidr"
]
);
peers = lib.mapAttrsToList (_machine: facts: {
publicKey = facts."wireguard.wg0.pub";
allowedIPs = [ facts."wireguard.wg0.cidr" ];
}) otherMachines;
2024-06-05 12:51:38 +02:00
in
2023-12-09 17:15:50 +01:00
{
networking.firewall.allowedUDPPorts = [ 51820 ];
2024-06-19 13:19:55 +02:00
clan.core.facts.services.wireguard = factsGenerator.wireguard { name = "wg0"; };
clan.core.facts.services.wireguard_ip = factsGenerator.public {
2024-06-07 09:34:23 +02:00
"wireguard.wg0.endpoint" = "95.216.66.212:51820";
"wireguard.wg0.cidr" = "10.100.0.1/24";
"wireguard.wg0.ip" = "10.100.0.1";
};
2024-06-07 08:45:08 +02:00
healthchecks.localCommands.ping-wg0 = pkgs.writers.writeBash "ping-wg0" ''
ping -c 1 -W 5 ${config.clan.core.facts.services.wireguard_ip.public."wireguard.wg0.ip".value}
'';
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)
2024-06-19 13:19:55 +02:00
privateKeyFile = config.clan.core.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
'';
2024-06-07 09:34:23 +02:00
peers = peers ++ [
2024-06-06 10:36:01 +02:00
# mobil devices
# -------------
2024-06-06 10:35:20 +02:00
# 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
}
2024-09-22 05:06:16 +02:00
{
# ipad tina
publicKey = "kuzUJn+lROh7ttA0qMc2p1abpfxjDGeYA+Ryzm88+AE=";
allowedIPs = [ "10.100.0.104/32" ];
}
2023-12-09 17:15:50 +01:00
];
};
};
}