2024-07-29 00:35:14 +02:00
|
|
|
{ inputs, lib, pkgs, config, ... }:
|
2023-10-23 07:47:06 +02:00
|
|
|
{
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
wireguard-tools
|
|
|
|
];
|
|
|
|
|
|
|
|
# NOTE: key generation
|
|
|
|
# umask 077
|
2024-01-08 22:44:22 +01:00
|
|
|
# wg genkey > key
|
|
|
|
# wg pubkey < key > key.pub
|
2023-10-23 07:47:06 +02:00
|
|
|
|
|
|
|
# Server
|
2024-01-08 22:44:22 +01:00
|
|
|
age.secrets."wireguard.privateKey" = {
|
2023-10-23 07:47:06 +02:00
|
|
|
mode = "077";
|
2024-01-08 22:44:22 +01:00
|
|
|
rekeyFile = "${inputs.self}/secrets/home/jeeves/wireguard/key.age";
|
2023-12-25 20:13:48 +01:00
|
|
|
generator = {
|
2024-05-04 21:47:38 +02:00
|
|
|
script = { lib, pkgs, file, ... }: /* bash */ ''
|
2023-12-25 20:13:48 +01:00
|
|
|
priv=$(${pkgs.wireguard-tools}/bin/wg genkey)
|
|
|
|
${pkgs.wireguard-tools}/bin/wg pubkey <<< "$priv" > ${lib.escapeShellArg (lib.removeSuffix ".age" file + ".pub")}
|
|
|
|
echo "$priv"
|
|
|
|
'';
|
|
|
|
};
|
2023-10-23 07:47:06 +02:00
|
|
|
};
|
|
|
|
|
2024-07-20 21:44:39 +02:00
|
|
|
# Enable NAT
|
|
|
|
networking.nat = {
|
|
|
|
enable = true;
|
|
|
|
enableIPv6 = true;
|
|
|
|
externalInterface = "eth0";
|
|
|
|
internalInterfaces = [ "wg0" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
# Open ports in the firewall
|
|
|
|
networking.firewall = {
|
|
|
|
allowedTCPPorts = [ 53 ];
|
|
|
|
allowedUDPPorts = [ 53 51820 ];
|
|
|
|
};
|
|
|
|
|
2023-10-23 07:47:06 +02:00
|
|
|
systemd.network = {
|
|
|
|
netdevs = {
|
|
|
|
"50-wg0" = {
|
|
|
|
netdevConfig = {
|
|
|
|
Kind = "wireguard";
|
|
|
|
Name = "wg0";
|
|
|
|
MTUBytes = "1300";
|
|
|
|
};
|
|
|
|
wireguardConfig = {
|
2024-01-08 22:44:22 +01:00
|
|
|
PrivateKeyFile = config.age.secrets."wireguard.privateKey".path;
|
2023-10-23 07:47:06 +02:00
|
|
|
ListenPort = 51820;
|
|
|
|
};
|
2024-01-08 22:44:22 +01:00
|
|
|
wireguardPeers =
|
|
|
|
lib.mapAttrsToList
|
2024-06-03 18:22:40 +02:00
|
|
|
(host: peerConfig: peerConfig)
|
2024-01-08 22:44:22 +01:00
|
|
|
{
|
|
|
|
cheetah = {
|
|
|
|
PublicKey = "CFTGvBcly791ClwyS6PzTjmqztvYJW2eklR7it/QhxI=";
|
|
|
|
AllowedIPs = [
|
|
|
|
"10.100.0.2/32"
|
|
|
|
"0.0.0.0/0"
|
|
|
|
# "::/0"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
limonka = {
|
|
|
|
PublicKey = "+x4cKc16KxhW/M3wv64FU1J0AkiLyXT5Oar6I1n1xk4=";
|
|
|
|
AllowedIPs = [
|
|
|
|
"10.100.0.3/32"
|
|
|
|
"0.0.0.0/0"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
peshoDjam = {
|
|
|
|
PublicKey = "37QEe3Lsq5BTIzxqAh9z7clHYeaOaMH31oqi5YvAPBY=";
|
|
|
|
AllowedIPs = [
|
|
|
|
"10.100.0.4/32"
|
|
|
|
"192.168.1.134/32"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
s42 = {
|
|
|
|
PublicKey = "pZF6M8TZ1FSBtTwFz4xzlMqwqRScEqgBfqHBk7ddixc=";
|
|
|
|
AllowedIPs = [
|
|
|
|
"10.100.0.5/32"
|
|
|
|
"0.0.0.0/0"
|
|
|
|
];
|
|
|
|
};
|
2024-03-17 22:43:11 +01:00
|
|
|
a41 = {
|
|
|
|
PublicKey = "/YEBfjDO+CfmYOKg9pO//ZAZQNutAS5z/Ggt2pX2gn0=";
|
|
|
|
AllowedIPs = [
|
|
|
|
"10.100.0.6/32"
|
|
|
|
"0.0.0.0/0"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
t410 = {
|
|
|
|
PublicKey = "YSTgtHXcvbCwYrnBCNujsTkLy+umVZWLGECtV88NIW0=";
|
|
|
|
AllowedIPs = [
|
|
|
|
"10.100.0.7/32"
|
|
|
|
"0.0.0.0/0"
|
|
|
|
];
|
|
|
|
};
|
2023-10-23 07:47:06 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-07-20 21:44:39 +02:00
|
|
|
|
2023-10-23 07:47:06 +02:00
|
|
|
networks.wg0 = {
|
|
|
|
matchConfig.Name = "wg0";
|
2024-01-25 16:39:43 +01:00
|
|
|
address = [ "10.100.0.1/24" ];
|
2023-10-23 07:47:06 +02:00
|
|
|
networkConfig = {
|
|
|
|
IPMasquerade = "ipv4";
|
2024-08-02 09:41:18 +02:00
|
|
|
IPv4Forwarding = true;
|
|
|
|
IPv6Forwarding = true;
|
2023-10-23 07:47:06 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|