From 84cf714b1e41414abdd5e38acbed3748a02507c7 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 22 Nov 2026 19:23:36 +0000 Subject: 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. --- configs/claude.nix | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'configs/claude.nix') 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 ]; } -- cgit v1.3.1