mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-29 16:24:10 +00:00
tailscale: only autoconnect after backend is up
Previously, if this service started before the backend is up, `StatusText` would be empty leading to the service trying to run `tailscale up` even if this device is already logged in.
This commit is contained in:
parent
71e91c409d
commit
185948bd01
@ -121,10 +121,16 @@ in {
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
};
|
||||
script = ''
|
||||
status=$(${config.systemd.package}/bin/systemctl show -P StatusText tailscaled.service)
|
||||
if [[ $status != Connected* ]]; then
|
||||
${cfg.package}/bin/tailscale up --auth-key 'file:${cfg.authKeyFile}' ${escapeShellArgs cfg.extraUpFlags}
|
||||
# https://github.com/tailscale/tailscale/blob/v1.72.1/ipn/backend.go#L24-L32
|
||||
script = let
|
||||
statusCommand = "${lib.getExe cfg.package} status --json | ${lib.getExe pkgs.jq} -r '.BackendState'";
|
||||
in ''
|
||||
while [[ "$(${statusCommand})" == "NoState" ]]; do
|
||||
sleep 0.5
|
||||
done
|
||||
status=$(${statusCommand})
|
||||
if [[ "$status" == "NeedsLogin" || "$status" == "NeedsMachineAuth" ]]; then
|
||||
${lib.getExe cfg.package} up --auth-key 'file:${cfg.authKeyFile}' ${escapeShellArgs cfg.extraUpFlags}
|
||||
fi
|
||||
'';
|
||||
};
|
||||
@ -137,7 +143,7 @@ in {
|
||||
Type = "oneshot";
|
||||
};
|
||||
script = ''
|
||||
${cfg.package}/bin/tailscale set ${escapeShellArgs cfg.extraSetFlags}
|
||||
${lib.getExe cfg.package} set ${escapeShellArgs cfg.extraSetFlags}
|
||||
'';
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user