45 lines
1.3 KiB
Nix
45 lines
1.3 KiB
Nix
{
|
|
pkgs,
|
|
config,
|
|
factsGenerator,
|
|
clanLib,
|
|
...
|
|
}:
|
|
{
|
|
|
|
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}
|
|
'';
|
|
|
|
networking.firewall.allowedUDPPorts = [ 51820 ];
|
|
clan.core.facts.services.wireguard = factsGenerator.wireguard { name = "wg0"; };
|
|
clan.core.facts.services.wireguard_ip = factsGenerator.public {
|
|
"wireguard.wg0.cidr" = "10.100.0.2/32";
|
|
"wireguard.wg0.ip" = "10.100.0.2";
|
|
};
|
|
|
|
# Enable WireGuard
|
|
networking.wg-quick.interfaces = {
|
|
# Hub and Spoke Setup
|
|
# https://www.procustodibus.com/blog/2020/11/wireguard-hub-and-spoke-config/
|
|
wg0 = {
|
|
address = [
|
|
config.clan.core.facts.services.wireguard_ip.public."wireguard.wg0.cidr".value
|
|
];
|
|
listenPort = 51820; # to match firewall allowedUDPPorts (without this wg uses random port numbers)
|
|
privateKeyFile = config.clan.core.facts.services.wireguard.secret."wireguard.wg0.key".path;
|
|
mtu = 1280;
|
|
|
|
peers = [
|
|
{
|
|
publicKey = clanLib.readFact "wireguard.wg0.pub" "orbi";
|
|
allowedIPs = [
|
|
(clanLib.readFact "wireguard.wg0.cidr" "orbi")
|
|
];
|
|
endpoint = clanLib.readFact "wireguard.wg0.endpoint" "orbi";
|
|
persistentKeepalive = 25;
|
|
}
|
|
];
|
|
};
|
|
};
|
|
}
|