53 lines
1.5 KiB
Nix
53 lines
1.5 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
port = 51820;
|
|
in
|
|
{
|
|
options.my.services.wireguard.enable = lib.mkEnableOption "enable";
|
|
config = lib.mkIf config.my.services.wireguard.enable {
|
|
sops.secrets."wireguard/private".sopsFile = ../../secrets/wireguard.yaml;
|
|
networking = {
|
|
firewall.allowedUDPPorts = [ port ];
|
|
nat = {
|
|
enable = true;
|
|
externalInterface = "enp2s0";
|
|
internalInterfaces = [ "wg0" ];
|
|
};
|
|
wireguard.interfaces.wg0 = {
|
|
ips = [ "10.100.0.1/24" ];
|
|
listenPort = port;
|
|
postSetup = ''
|
|
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o eth0 -j MASQUERADE
|
|
'';
|
|
postShutdown = ''
|
|
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s 10.100.0.0/24 -o eth0 -j MASQUERADE
|
|
'';
|
|
privateKeyFile = config.sops.secrets."wireguard/private".path;
|
|
peers = [
|
|
{
|
|
publicKey = "ciupBjCcIpd3K5vlzNMJC8iiyNqB9xXwkSC6UXPKP3g=";
|
|
allowedIPs = [ "10.100.0.2/32" ];
|
|
} # phone
|
|
{
|
|
publicKey = "JgeA1ElDwR7oLmyGn8RzvxiscMBhR8+L+mEjY1Cq7gk=";
|
|
allowedIPs = [ "10.100.0.3/32" ];
|
|
} # tablet
|
|
{
|
|
publicKey = "TinYhzLh4D+bX7RTwj/Ww3V0JdaTuD114jhgCWCWW1I=";
|
|
allowedIPs = [ "10.100.0.15/32" ];
|
|
} # joy
|
|
{
|
|
publicKey = "92JdW/NExg1tUE4cEyl6Yn+0Eex+iFVA37ahPRhRnRM=";
|
|
allowedIPs = [ "10.100.0.16/32" ];
|
|
} # gorilia
|
|
];
|
|
};
|
|
};
|
|
};
|
|
}
|