Compare commits

...

2 commits

Author SHA1 Message Date
2c45da4844 Server/tailscale: wait to get ip address 2024-08-16 19:57:08 +02:00
16fa01ad7d Server/Caddy: start after tailscale:x 2024-08-16 19:54:39 +02:00
2 changed files with 18 additions and 3 deletions

View file

@ -50,9 +50,9 @@ in {
"${downloadsHostname},everest"
];
systemd = {
units.tailscaled.requiredBy = ["caddy.service"];
services.caddy.after = ["tailscaled.service"];
# We have somewhat frequent power outages, and our ISP router takes
# ages to boot up. If I don't add a delay, traefik tries to bind to
# ages to boot up. If I don't add a delay, caddy tries to bind to
# the tailscale interface before it's ready, making it crash too much
# in too little time
services.caddy.serviceConfig.RestartSec = lib.mkForce "120s";

View file

@ -1,6 +1,21 @@
{...}: {
{pkgs, ...}: let
script = pkgs.writeShellApplication {
name = "tailscale-wait-for-ip";
runtimeInputs = [pkgs.iproute2];
text = ''
# Based on https://github.com/tailscale/tailscale/issues/11504#issuecomment-2113331262
echo Waiting for tailscale0 to get an IP adress..
for i in {1..15}; do
if ip addr show dev tailscale0 | grep -q 'inet '; then break; fi
echo "$i"
sleep 1
done
'';
};
in {
services.tailscale = {
# This is needed for being an exit node
useRoutingFeatures = "server";
};
systemd.services.tailscaled.postStart = "${script}/bin/tailscale-wait-for-ip";
}