2023-12-25 14:17:30 +01:00
|
|
|
{ inputs, outputs, lib, pkgs, config, ... }:
|
2023-10-23 07:47:06 +02:00
|
|
|
{
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
wireguard-tools
|
|
|
|
];
|
|
|
|
|
|
|
|
# NOTE: key generation
|
|
|
|
# umask 077
|
|
|
|
# wg genkey > private
|
|
|
|
# wg pubkey < private > public
|
|
|
|
|
|
|
|
# Server
|
2023-12-25 14:17:30 +01:00
|
|
|
age.secrets."wireguard.private" = {
|
2023-10-23 07:47:06 +02:00
|
|
|
mode = "077";
|
2023-12-25 14:17:30 +01:00
|
|
|
rekeyFile = "${inputs.self}/secrets/home/jeeves/wireguard/private.age";
|
2023-12-25 18:06:20 +01:00
|
|
|
generator = {lib, pkgs, file, ...}: ''
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.allowedUDPPorts = [51820];
|
|
|
|
systemd.network = {
|
|
|
|
netdevs = {
|
|
|
|
"50-wg0" = {
|
|
|
|
netdevConfig = {
|
|
|
|
Kind = "wireguard";
|
|
|
|
Name = "wg0";
|
|
|
|
MTUBytes = "1300";
|
|
|
|
};
|
|
|
|
wireguardConfig = {
|
2023-12-25 14:17:30 +01:00
|
|
|
PrivateKeyFile = config.age.secrets."wireguard.private".path;
|
2023-10-23 07:47:06 +02:00
|
|
|
ListenPort = 51820;
|
|
|
|
};
|
|
|
|
wireguardPeers = [
|
|
|
|
{
|
|
|
|
# cheetah
|
|
|
|
wireguardPeerConfig = {
|
2023-10-23 08:24:31 +02:00
|
|
|
PublicKey = "CFTGvBcly791ClwyS6PzTjmqztvYJW2eklR7it/QhxI=";
|
2023-10-23 07:47:06 +02:00
|
|
|
AllowedIPs = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
# "::/0"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
2023-11-17 15:03:25 +01:00
|
|
|
{
|
|
|
|
# limonka
|
|
|
|
wireguardPeerConfig = {
|
|
|
|
PublicKey = "+x4cKc16KxhW/M3wv64FU1J0AkiLyXT5Oar6I1n1xk4=";
|
|
|
|
AllowedIPs = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
# "192.168.1.0/24"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
# s42
|
|
|
|
wireguardPeerConfig = {
|
|
|
|
PublicKey = "pZF6M8TZ1FSBtTwFz4xzlMqwqRScEqgBfqHBk7ddixc=";
|
|
|
|
AllowedIPs = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
2023-10-23 07:47:06 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
networks.wg0 = {
|
|
|
|
matchConfig.Name = "wg0";
|
|
|
|
address = ["10.100.0.1/24"];
|
|
|
|
networkConfig = {
|
|
|
|
IPMasquerade = "ipv4";
|
|
|
|
IPForward = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|