1
0
Fork 0

sail: Add tailscale

This commit is contained in:
Daniel Kempkens 2022-07-31 14:03:27 +02:00
parent 20d7b2c066
commit b100e88fdd
3 changed files with 32 additions and 0 deletions

Binary file not shown.

View file

@ -9,6 +9,7 @@ in
../nixos/ssh.nix ../nixos/ssh.nix
../nixos/git.nix ../nixos/git.nix
../nixos/tailscale.nix
../nixos/arion.nix ../nixos/arion.nix
../../container/webserver ../../container/webserver

View file

@ -0,0 +1,31 @@
{ pkgs, secret, ... }:
{
environment.systemPackages = [ pkgs.tailscale ];
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 = ''
# wait for tailscaled to settle
sleep 2
# check if we are already authenticated to tailscale
status="$(${pkgs.tailscale}/bin/tailscale status -json | ${pkgs.jq}/bin/jq -r .BackendState)"
if [ $status = "Running" ]; then # if so, then do nothing
exit 0
fi
# otherwise authenticate with tailscale
${pkgs.tailscale}/bin/tailscale up -authkey ${secret.tailscale.key}
'';
};
}