{ config, pkgs, ... }: { age.secrets.tailscale-auth = { file = ../secrets/tailscale-auth.age; owner = "root"; }; services.tailscale.enable = true; systemd.services.tailscale-autoconnect = { description = "Automatic connection to Tailscale"; after = [ "network-pre.target" "tailscale.service" ]; wants = [ "network-pre.target" "tailscale.service" ]; wantedBy = [ "multi-user.target" ]; serviceConfig.Type = "oneshot"; script = '' sleep 2 status="$(${pkgs.tailscale}/bin/tailscale status -json | ${pkgs.jq}/bin/jq -r .BackendState)" if [ "$status" = "Running" ]; then exit 0; fi ${pkgs.tailscale}/bin/tailscale up --authkey file:${config.age.secrets.tailscale-auth.path} ''; }; networking.firewall.trustedInterfaces = [ "tailscale0" ]; networking.firewall.allowedUDPPorts = [ 41641 ]; }