diff options
Diffstat (limited to 'configs')
| -rw-r--r-- | configs/claude.nix | 30 |
1 files changed, 26 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 ]; } |
