config/profiles/vpn-pbsds/tailscale.nix

36 lines
1.1 KiB
Nix
Raw Permalink Normal View History

2024-01-27 03:47:28 +01:00
{ config, pkgs, lib, ...}:
let
cfg = config.services.tailscale;
inherit (lib) mkIf getExe;
in
2024-01-26 23:59:48 +01:00
{
services.tailscale.enable = true;
networking.firewall.checkReversePath = "loose";
2024-01-27 03:47:28 +01:00
networking.firewall.trustedInterfaces = [ cfg.interfaceName ];
networking.firewall.allowedUDPPorts = [ cfg.port ];
2024-01-26 23:59:48 +01:00
2024-01-27 03:47:28 +01:00
/** /
systemd.services."tailscale-autoconnect" = mkIf cfg.enable {
serviceConfig.Type = "oneshot";
after = [ "network-pre.target" "tailscale.service" ];
wants = [ "network-pre.target" "tailscale.service" ];
wantedBy = [ "tailscale.service" ];
script = ''
sleep 60 # Wait for tailscaled to settle
2024-01-26 23:59:48 +01:00
2024-01-27 03:47:28 +01:00
status="$(${getExe cfg.package} status -json | ${getExe pkgs.jq} -r .BackendState)"
if [ $status = "Running" ]; then
exit 0 # already authenticated
fi
#${getExe cfg.package} up -authkey tskey-examplekeyhere
'';
};
/**/
# remote sudo nixos-rebuild switch --flake . -L
# remote-quick sudo tailscale up --login-server 'https://head.pbsds.net'
# ssh noximilien.pbsds.net sudo headscale --namespace 'ts' nodes register --key <machine_key>
2024-01-26 23:59:48 +01:00
}