summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-22 19:23:36 +0000
committertv <tv@krebsco.de>2026-11-22 19:37:36 +0000
commit84cf714b1e41414abdd5e38acbed3748a02507c7 (patch)
tree3438ea29dcffdbf49b6c1ed9e96592da66b4805e
parentf446498e11f087c66fb9b0e53a707c493f46d217 (diff)
configs/claude: the remotes wait for the login
Remote Control needs a login, and the units answer its questions in ~/.claude.json, which may come before it: so the units have ConditionPathExists on ~/.claude/.credentials.json (skipped, not failed, before the login), and a path unit on it starts the restore service, which starts the static remotes now, too, and the dynamic ones: at boot, if there's a login already, or else as soon as there is. The restore service isn't multi-user.target's anymore, and remains active, once done, so the path unit starts it once. claude-remote start refuses before the login, as the unit would be skipped, and forgotten.
-rw-r--r--configs/claude.nix30
-rw-r--r--pkgs/claude-remote.nix3
2 files changed, 29 insertions, 4 deletions
diff --git a/configs/claude.nix b/configs/claude.nix
index b7ebb75..0cbc1ae 100644
--- a/configs/claude.nix
+++ b/configs/claude.nix
@@ -11,8 +11,9 @@
# for Claude Code (sessions, memory, trust), on the repositories in ~/src,
# which all remotes share. Each runs as claude in a tmux of its own,
# which root opens with claude-remote attach [NAME]. Once, as root:
-# runuser -l claude -c 'claude auth login'. Remote Control's questions
-# (enable it, once per machine; trust ~/remotes/NAME) the unit answers.
+# runuser -l claude -c 'claude auth login', which the remotes wait for
+# (see login). Remote Control's questions (enable it, once per
+# machine; trust ~/remotes/NAME) the unit answers.
# The state is in /home/claude, i.e. on the run script's --home drive,
# which is required.
{ config, lib, pkgs, ... }:
@@ -46,6 +47,10 @@ let
# shutdown). Below /home/.var/lib/claude, the claude facet's part of
# what would be in /var/lib (which is on the tmpfs), on the home drive:
# root's, and readable for anyone.
+ # The login (runuser -l claude -c 'claude auth login'), which the
+ # remotes wait for: Remote Control needs it, and ~/.claude.json, which
+ # their units answer its questions in, may come before.
+ login = "/home/claude/.claude/.credentials.json";
stateDir = "/home/.var/lib/claude/remote-control";
# The remotes that were static at the last boot, so that the restore
# service makes the ones that aren't anymore dynamic, and they go on.
@@ -117,6 +122,9 @@ in
wants = [ "network-online.target" ];
after = [ "network-online.target" "systemd-tmpfiles-setup.service" ];
unitConfig.RequiresMountsFor = "/home/claude";
+ # Not before the login (skipped, rather than failed): the restore
+ # service starts the remotes once there is one.
+ unitConfig.ConditionPathExists = login;
# Without the drive, there's no mount to require, and /home is on the
# tmpfs: fail rather than keep the state there.
unitConfig.AssertPathIsMountPoint = "/home";
@@ -190,13 +198,17 @@ in
# that are static now, which it forgets instead; and before that, makes
# the ones that were static at the last boot, but aren't anymore (taken
# out of the configuration), dynamic, so they go on running, as long as
- # they have a directory (to retire one: claude-remote stop NAME).
+ # they have a directory (to retire one: claude-remote stop NAME); and
+ # starts the static ones, too, which multi-user.target's start skipped
+ # if there was no login yet. Once per boot, by the path unit below,
+ # once there's a login.
systemd.services.claude-remote-control-restore = {
- wantedBy = [ "multi-user.target" ];
after = [ "systemd-tmpfiles-setup.service" ];
unitConfig.RequiresMountsFor = stateDir;
unitConfig.AssertPathIsMountPoint = "/home";
serviceConfig.Type = "oneshot";
+ # active, once done, so that the path unit doesn't start it again
+ serviceConfig.RemainAfterExit = true;
script = ''
if test -f ${staticFile}; then
for name in $(cat ${staticFile}); do
@@ -215,7 +227,17 @@ in
${systemctl} start --no-block "claude-remote-control@$name.service"
fi
done
+ for name in ${lib.escapeShellArgs static}; do
+ ${systemctl} start --no-block "claude-remote-control@$name.service"
+ done
'';
};
+ # The restore service, once there's a login: at boot, if there's one
+ # already, or else as soon as there is.
+ systemd.paths.claude-remote-control-restore = {
+ wantedBy = [ "multi-user.target" ];
+ unitConfig.RequiresMountsFor = "/home/claude";
+ pathConfig.PathExists = login;
+ };
environment.systemPackages = [ claude-remote ];
}
diff --git a/pkgs/claude-remote.nix b/pkgs/claude-remote.nix
index c692be1..d8975e6 100644
--- a/pkgs/claude-remote.nix
+++ b/pkgs/claude-remote.nix
@@ -432,6 +432,9 @@ let
;;
start)
name_arg "''${1-}"
+ # before the login, the unit would be skipped, and not come back
+ test -e "$home/.claude/.credentials.json" ||
+ die "there's no login yet: runuser -l claude -c 'claude auth login' (then the remotes start)"
systemctl start "$(unit "$1")"
if ! is_static "$1"; then
echo "$1 is dynamic: it lasts, across reboots, until claude-remote stop $1."