Tailscale setup

This commit is contained in:
Lucas Thelen 2025-09-26 05:03:59 +00:00
parent 4b1d75b0e0
commit b7eee0a829
5 changed files with 134 additions and 1 deletions

32
networking/vpn-host.nix Normal file
View file

@ -0,0 +1,32 @@
{ config, lib, pkgs, ... }: {
environment.systemPackages = [ pkgs.tailscale ];
services.tailscale.enable = true;
systemd.services.tailscale-autoconnect = {
description = "Automatic oneshot connection to tailscale";
after = [ "network-pre.target" "tailscale.service" ];
wants = [ "network-pre.target" "tailscale.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig.Type = "oneshot";
script = with pkgs; ''
sleep 2
status="$(${tailscale}/bin/tailscale status -json | ${jq}/bin/jq -r .BackendState)"
if [ $status = "Running" ]; then # if so, then do nothing
exit 0
fi
${tailscale}/bin/tailscale up -authkey ${config.age.secrets.tailscale.path}
'';
};
networking.firewall = {
trustedInterfaces = [ "tailscale0" ];
allowedUDPPorts = [ config.services.tailscale.port ];
allowedTCPPorts = [ 22 ];
};
}