Skip to content

Commit 57a28bb

Browse files
committed
fix(hosts/shared): tailscaled-autoconnect delaying rebuilds
If tailscale was not up on purpose this service would hang for 60 seconds.
1 parent d5df6b2 commit 57a28bb

File tree

2 files changed

+61
-36
lines changed

2 files changed

+61
-36
lines changed

home/racci/features/desktop/hyprland/menus/caelestia.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,7 @@ in
243243
};
244244
};
245245

246+
# This doesn't work very well, needs a file manually moving to the persist dir first
247+
# Caelestia doesn't respect an existing symlink and will just overwrite it.
246248
user.persistence.files = [ ".face" ];
247249
}

hosts/shared/optional/tailscale.nix

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,45 +32,68 @@
3232
++ (lib.optional config.host.device.isVirtual "virtual")
3333
++ (lib.optional config.host.device.isHeadless "headless");
3434
};
35+
systemd = {
36+
services = {
37+
tailscaled-autoconnect = {
38+
serviceConfig.ExecCondition = lib.getExe (
39+
pkgs.writeShellApplication {
40+
name = "tailscale-check-condition";
41+
runtimeInputs = [
42+
pkgs.tailscale
43+
pkgs.jq
44+
];
45+
text = ''
46+
STATE=$(tailscale status --json --peers=false | jq -r .BackendState)
47+
if [ "$STATE" == "NeedsLogin" ]; then
48+
exit 0
49+
else
50+
exit 1
51+
fi
52+
'';
53+
}
54+
);
55+
};
3556

36-
systemd.services.tailscale-check = {
37-
description = "Check Tailscale login status";
38-
after = [ "tailscaled.service" ];
39-
wants = [ "tailscaled.service" ];
40-
serviceConfig = {
41-
Type = "oneshot";
42-
User = "root";
43-
ExecStart = lib.getExe (
44-
pkgs.writeShellApplication {
45-
name = "tailscale-check";
46-
runtimeInputs = [
47-
pkgs.tailscale
48-
pkgs.systemd
49-
pkgs.jq
50-
];
51-
text = ''
52-
STATE=$(tailscale status --json --peers=false | jq -r .BackendState)
53-
if [ "$STATE" == "NeedsLogin" ]; then
54-
echo "Tailscale is not logged in. Running tailscaled-autoconnect service."
55-
systemctl start tailscaled-autoconnect.service
56-
else
57-
echo "Tailscale is logged in."
58-
fi
59-
'';
60-
}
61-
);
57+
tailscale-check = {
58+
description = "Check Tailscale login status";
59+
after = [ "tailscaled.service" ];
60+
wants = [ "tailscaled.service" ];
61+
serviceConfig = {
62+
Type = "oneshot";
63+
User = "root";
64+
ExecStart = lib.getExe (
65+
pkgs.writeShellApplication {
66+
name = "tailscale-check";
67+
runtimeInputs = [
68+
pkgs.tailscale
69+
pkgs.systemd
70+
pkgs.jq
71+
];
72+
text = ''
73+
STATE=$(tailscale status --json --peers=false | jq -r .BackendState)
74+
if [ "$STATE" == "NeedsLogin" ]; then
75+
echo "Tailscale is not logged in. Running tailscaled-autoconnect service."
76+
systemctl start tailscaled-autoconnect.service
77+
else
78+
echo "Tailscale is logged in."
79+
fi
80+
'';
81+
}
82+
);
83+
};
84+
};
6285
};
63-
};
6486

65-
systemd.timers.tailscale-check = {
66-
description = "Periodically check Tailscale login status";
67-
wantedBy = [ "timers.target" ];
68-
after = [ "tailscaled.service" ];
69-
requires = [ "tailscaled.service" ];
70-
timerConfig = {
71-
OnStartupSec = "30s";
72-
OnUnitActiveSec = "20m";
73-
Persistent = true;
87+
timers.tailscale-check = {
88+
description = "Periodically check Tailscale login status";
89+
wantedBy = [ "timers.target" ];
90+
after = [ "tailscaled.service" ];
91+
requires = [ "tailscaled.service" ];
92+
timerConfig = {
93+
OnStartupSec = "30s";
94+
OnUnitActiveSec = "20m";
95+
Persistent = true;
96+
};
7497
};
7598
};
7699

0 commit comments

Comments
 (0)