diff --git a/AGENTS.md b/AGENTS.md index cf91f3a..534587b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,8 +58,8 @@ Common ones: - `ssh-machine [cmd]` — SSH to a NixOS system or home-manager config by name. Resolves the target and ssh options (identity, port) from its deploy-rs node, so it needs `my.deploy.enable` (same gate as `deploy`). Connection settings for all nodes are cached together and invalidated - by tracked Git changes; use `ssh-machine --refresh` to force a refresh - (see `docs/deployment.md#ssh-machine`). + by checkout changes (the jj working copy, else tracked Git changes); use + `ssh-machine --refresh` to force a refresh (see `docs/deployment.md#ssh-machine`). Boxes default to the `fish` login shell, so pipe multi-statement remote scripts through `bash` (e.g. `ssh-machine bash -s < script.sh`) rather than `&&`/`for`. If outbound SSH hangs at the publickey step (flaky `ssh-agent`), disable the agent for the call: diff --git a/devshell/commands.nix b/devshell/commands.nix index 25b6034..988fc85 100644 --- a/devshell/commands.nix +++ b/devshell/commands.nix @@ -4,7 +4,7 @@ let devKey = ".keys/dev.key"; sshMachine = pkgs.writeShellApplication { name = "ssh-machine"; - runtimeInputs = with pkgs; [ coreutils git jq openssh ]; + runtimeInputs = with pkgs; [ coreutils git jujutsu jq openssh ]; text = builtins.readFile ./ssh-machine.sh; }; in diff --git a/devshell/ssh-machine.sh b/devshell/ssh-machine.sh index fc70a9f..f6ec369 100644 --- a/devshell/ssh-machine.sh +++ b/devshell/ssh-machine.sh @@ -20,11 +20,17 @@ cache_dir=.cache/ssh-machine cache=$cache_dir/connections.json fingerprint() { - { - git rev-parse HEAD && - git diff --no-ext-diff --no-textconv --binary HEAD -- && - git diff --no-ext-diff --no-textconv --binary --cached -- - } | sha256sum | cut -d ' ' -f 1 + # A jj working-copy commit's ID covers its whole snapshotted tree, so it changes with any + # working-copy edit. This also works in secondary workspaces, which have no Git checkout. + if jj root >/dev/null 2>&1; then + jj log --no-pager --color never --no-graph -r @ -T 'commit_id' + else + { + git rev-parse HEAD && + git diff --no-ext-diff --no-textconv --binary HEAD -- && + git diff --no-ext-diff --no-textconv --binary --cached -- + } | sha256sum | cut -d ' ' -f 1 + fi } key=$(fingerprint) diff --git a/docs/deployment.md b/docs/deployment.md index b9a1021..fdfb306 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -60,11 +60,12 @@ Generated profiles deploy in this order: `ssh-machine [cmd]` resolves `user@host` and the merged global/node `sshOpts` from `.#deploy`, using the same `my.deploy.enable` gate and `@` → `-at-` mangling as `deploy`, then runs `ssh`. Connection settings for all nodes are cached together in `.cache/ssh-machine/`; -normal connections read the cache without running Nix. A fingerprint of Git HEAD and -staged/unstaged tracked changes automatically invalidates it, including newly added files -after `git add`. -Untracked and ignored files do not affect the fingerprint. Any tracked edit, even an unrelated -one, causes the next connection to refresh all nodes. Use `ssh-machine --refresh` to force a +normal connections read the cache without running Nix. A fingerprint of the checkout +automatically invalidates it. In a Jujutsu workspace (including secondary workspaces without a +Git checkout) it is the working-copy commit ID, so any snapshotted change counts, including new +files that are not ignored. In a Git-only checkout it is HEAD plus staged/unstaged tracked +changes; untracked files only count after `git add`. Ignored files never affect the fingerprint. +Any such edit, even an unrelated one, causes the next connection to refresh all nodes. Use `ssh-machine --refresh` to force a refresh, or `ssh-machine --refresh [cmd]` to refresh and connect. Refresh failures stop the command; the previous cache is never used as a fallback.