2023-10-19 18:55:56 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
psCfg = config.pub-solar;
|
|
|
|
cfg = config.pub-solar.wireguard-client;
|
|
|
|
in {
|
|
|
|
options.pub-solar.wireguard-client = {
|
|
|
|
ownIPs = mkOption {
|
|
|
|
description = ''
|
|
|
|
Internal ips in wireguard used for cluster control-plane communication.
|
|
|
|
'';
|
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
wireguardPrivateKeyFile = mkOption {
|
|
|
|
description = ''
|
|
|
|
Location of private key file
|
|
|
|
'';
|
|
|
|
type = types.path;
|
|
|
|
};
|
2024-01-05 14:06:49 +00:00
|
|
|
|
2024-02-04 00:05:28 +00:00
|
|
|
useDNS = mkOption {
|
|
|
|
description = ''
|
|
|
|
Whether to use the wireguard DNS
|
|
|
|
'';
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
2024-01-05 14:06:49 +00:00
|
|
|
fullTunnel = mkOption {
|
|
|
|
description = ''
|
|
|
|
Whether to tunnel all traffic through the wireguard VPN
|
|
|
|
'';
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2023-10-19 18:55:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
networking.firewall.allowedUDPPorts = [51899];
|
|
|
|
|
2024-02-04 00:05:28 +00:00
|
|
|
systemd.services.wireguard-wg0 = {
|
2023-11-06 20:43:48 +00:00
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"network-online.target"
|
|
|
|
"nss-lookup.target"
|
|
|
|
];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = mkForce "simple";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "30";
|
|
|
|
};
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
WG_ENDPOINT_RESOLUTION_RETRIES = "infinity";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-02-04 00:05:28 +00:00
|
|
|
networking.wireguard.interfaces = {
|
2023-10-19 18:55:56 +00:00
|
|
|
wg0 = {
|
2023-10-19 22:47:11 +00:00
|
|
|
listenPort = 51899;
|
2024-02-04 00:05:28 +00:00
|
|
|
mtu = 1300;
|
|
|
|
ips = cfg.ownIPs;
|
2023-10-19 18:55:56 +00:00
|
|
|
privateKeyFile = cfg.wireguardPrivateKeyFile;
|
2024-02-04 00:05:28 +00:00
|
|
|
postSetup = ''
|
|
|
|
printf "nameserver 10.0.1.7\nnameserver fd00:b12f:acab:1312:acab:7::" | resolvconf -a wg0 -m 0 -x
|
|
|
|
'';
|
|
|
|
postShutdown = ''
|
|
|
|
resolvconf -d wg0 -f
|
|
|
|
'';
|
2023-10-19 18:55:56 +00:00
|
|
|
peers = [
|
|
|
|
{
|
2023-10-24 15:56:14 +00:00
|
|
|
# frikandel
|
|
|
|
publicKey = "p6YKNYBlySKfhTN+wbSsKdoNjzko/XSAiTAlCJzP1jA=";
|
2023-10-25 11:23:13 +00:00
|
|
|
allowedIPs = [
|
|
|
|
"10.0.1.0/24"
|
2023-10-26 13:10:54 +00:00
|
|
|
"fd00:b12f:acab:1312::/64"
|
2024-01-05 14:06:49 +00:00
|
|
|
] ++ (if cfg.fullTunnel then [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
"::/0"
|
|
|
|
] else []);
|
2023-11-01 15:27:29 +00:00
|
|
|
endpoint = "vpn.b12f.io:51899";
|
2023-10-19 18:55:56 +00:00
|
|
|
persistentKeepalive = 25;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|