diff options
| -rw-r--r-- | configs/claude.nix | 19 | ||||
| -rw-r--r-- | pkgs/claude-remote.nix | 3 |
2 files changed, 19 insertions, 3 deletions
diff --git a/configs/claude.nix b/configs/claude.nix index 205078b..345a70a 100644 --- a/configs/claude.nix +++ b/configs/claude.nix @@ -5,7 +5,8 @@ # systemd.targets.multi-user.wants = [ "claude-remote-control@NAME.service" ]; # or with claude-remote start NAME (root's tool for the remotes, see # pkgs/claude-remote.nix), which lasts, across reboots, until -# claude-remote stop NAME (see stateDir). +# claude-remote stop NAME (see stateDir). One taken out of the layers +# goes on like that, too, after the reboot (see staticFile). # A remote is a context: it works in ~/remotes/NAME, which is its project # 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, @@ -46,6 +47,9 @@ let # what would be in /var/lib (which is on the tmpfs), on the home drive: # root's, and readable for anyone. 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. + staticFile = "/home/.var/lib/claude/static-remotes"; static = map (u: lib.removeSuffix ".service" (lib.removePrefix "claude-remote-control@" u)) (lib.filter (lib.hasPrefix "claude-remote-control@") config.systemd.targets.multi-user.wants); systemctl = "${config.systemd.package}/bin/systemctl"; @@ -168,7 +172,10 @@ in }; # Starts the remotes in stateDir again, after a reboot, but for those - # that are static now, which it forgets instead. + # 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). systemd.services.claude-remote-control-restore = { wantedBy = [ "multi-user.target" ]; after = [ "systemd-tmpfiles-setup.service" ]; @@ -176,6 +183,14 @@ in unitConfig.AssertPathIsMountPoint = "/home"; serviceConfig.Type = "oneshot"; script = '' + if test -f ${staticFile}; then + for name in $(cat ${staticFile}); do + if ! ${isStatic "$name"} && test -d /home/claude/remotes/"$name"; then + touch ${stateDir}/"$name" + fi + done + fi + printf '%s\n' ${lib.escapeShellArgs static} > ${staticFile} for f in ${stateDir}/*; do test -f "$f" || continue name=''${f##*/} diff --git a/pkgs/claude-remote.nix b/pkgs/claude-remote.nix index ff49102..c692be1 100644 --- a/pkgs/claude-remote.nix +++ b/pkgs/claude-remote.nix @@ -71,7 +71,8 @@ let Kinds: static started by the system's configuration - dynamic started here: lasts, across reboots, until stopped here + dynamic started here, or static until taken out of the + configuration: lasts, across reboots, until stopped here - neither: stopped, or not started yet EOF } |
