Checksum watched files by repo-relative path - #171
Open
omnibs wants to merge 2 commits into
Open
Conversation
The cache signature (the hash in the cache.<sig> filename) and the freshness comparison both serialize each watched file's PathBuf. Since watch_files() absolutizes against the build directory, a cache built in one checkout could never be fresh in another: identical trees at different paths (e.g. linked git worktrees) produced different sums, so a cloned, byte-for-byte-current cache still reported "Nix environment is out of date" on every load. Store paths relative to the build directory instead. Content hashes are unchanged; the hook absolutizes the (possibly relative) paths against the build directory when emitting watch_file lines, so direnv still watches the right files wherever the cache came from. Paths outside the build directory are kept absolute. Caches written by older versions keep working through the fallback symlink: they compare as stale once (their sums carry absolute paths), and the next `firstaide build` writes a portable cache. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR makes the checksum (and derived cache signature) portable across different checkouts of the same working tree by storing watched file paths relative to the build directory, eliminating stale-cache behavior when the repo is located at a different absolute path.
Changes:
- Make
Checksums/Checksumserialize watched paths relative to a provided root directory (keeping paths outside the root absolute). - Update commands that compute checksums to pass
config.build_diras the root and update the hook to absolutize stored paths when emittingwatch_fileentries. - Bump crate version to
0.1.7and add unit tests covering root-relative and outside-root path behavior.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/sums.rs | Store checksum paths root-relative and add tests ensuring portability across different roots. |
| src/config.rs | Expose abspath so other commands can absolutize stored (now-relative) watch paths. |
| src/cmds/status.rs | Compute checksums using a root (build dir) for consistent signatures. |
| src/cmds/hook.rs | Absolutize cached watch paths when generating direnv watch_file directives. |
| src/cmds/build.rs | Compute checksums using a root (build dir) so cache keys don’t depend on absolute checkout location. |
| Cargo.toml | Bump package version to 0.1.7. |
| Cargo.lock | Update locked package version to 0.1.7. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
macos-11 was retired from GitHub's hosted runner pool, so that leg of the matrix never got a runner and sat queued until the 24h timeout. Switch to macos-latest, and bump actions/checkout and install-nix-action off their Node 20 versions. Note: macos-latest is arm64, so nix-build now targets aarch64-darwin for the first time. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A cache built in one checkout can never be fresh in another:
Checksumserializes each watched file's absolute path, so identical trees at different paths (e.g. linked git worktrees warmed by cloning_build/firstaidefrom the main checkout) get a differentcache.<sig>name and fail thesums::equalfreshness check. Result: "Nix environment is out of date! … Loading STALE environment" on every single load, even when the cache is byte-for-byte current.This stores checksum paths relative to the build directory instead. Content hashes are unchanged. The hook absolutizes the paths against the build dir when emitting
watch_filelines, so direnv still watches the right files wherever the cache came from. Paths outside the build dir stay absolute.Old caches degrade gracefully: they still load through the
cachesymlink fallback, compare stale once, and the nextfirstaide buildwrites a portable cache. Bumped the version to 0.1.7 since existing cache signatures all change.Verified with a synthetic project — cache built in
tree-a, tree copied totree-bat a different path:and the upgrade path (new binary on an old-format cache): stale once, up to date after one rebuild.