wireguard: let tunnel wait for private network

This commit is contained in:
Benjamin Yule Bädorf 2024-03-27 15:22:46 +01:00
parent e609bafe8b
commit b9f0063993
Signed by: b12f
GPG key ID: 729956E1124F8F26
2 changed files with 22 additions and 5 deletions

View file

@ -45,7 +45,7 @@ in {
networking.firewall.allowedUDPPorts = [51899]; networking.firewall.allowedUDPPorts = [51899];
systemd.services.wireguard-wg-private = { systemd.services.wireguard-wg-private = {
after = [ wantedBy = [
"network.target" "network.target"
"network-online.target" "network-online.target"
"nss-lookup.target" "nss-lookup.target"
@ -54,7 +54,7 @@ in {
serviceConfig = { serviceConfig = {
Type = mkForce "simple"; Type = mkForce "simple";
Restart = "on-failure"; Restart = "on-failure";
RestartSec = "30"; RestartSec = "10";
}; };
environment = { environment = {
@ -98,7 +98,6 @@ in {
"::/0" "::/0"
] else []); ] else []);
endpoint = "vpn.b12f.io:51899"; endpoint = "vpn.b12f.io:51899";
persistentKeepalive = 30;
dynamicEndpointRefreshSeconds = 30; dynamicEndpointRefreshSeconds = 30;
} }
]; ];

View file

@ -41,8 +41,26 @@ in {
config = mkIf (length cfg.ownIPs != 0){ config = mkIf (length cfg.ownIPs != 0){
networking.firewall.allowedUDPPorts = [51820]; networking.firewall.allowedUDPPorts = [51820];
systemd.services.wireguard-wg-tunnel = mkIf (length config.pub-solar.wireguard.private.ownIPs != 0) { systemd.services.wireguard-wg-tunnel = {
after = [ "wireguard-wg-private.service" ]; after = [
"network.target"
"network-online.target"
"nss-lookup.target"
];
wants = [
"wireguard-wg-private.service"
];
preStart = ''
while true; do
if ${pkgs.netcat}/bin/nc -w 5 -z 10.13.12.7 22 2>/dev/null; then
exit 0;
else
sleep 1;
fi
done;
'';
serviceConfig = { serviceConfig = {
Type = mkForce "simple"; Type = mkForce "simple";