Skip to content

ci(nix): refresh the vscode npmDepsHash automatically - #2283

Closed
robcohen wants to merge 1 commit into
mainfrom
ci/automate-vscode-npm-deps-hash
Closed

robcohen wants to merge 1 commit into
mainfrom
ci/automate-vscode-npm-deps-hash

Conversation

@robcohen

@robcohen robcohen commented Sep 8, 2026

Copy link
Copy Markdown
Member

flake.nix pins npmDepsHash over packages/vscode/package-lock.json, because buildNpmPackage hashes the vendored dependency tree. Dependabot updates the lockfile and has no way to know a Nix expression hashes it, so every npm bump to that package lands red:

error: hash mismatch in fixed-output derivation
         specified: sha256-Oc3yvMFep3AogJpFa5Ji4zIMXCIF/PGLJc7AM98mr7w=
            got:    sha256-RAG2KxhwVzCbaywKCclZHf5ySBdA/RBjbtd7NPAV+2c=

That is #2109, #2202, #2243, and both dependabot PRs open right now (#2269, #2272). build requires the VS Code Extension (Nix) job, so none of them can merge unattended.

There was no tooling for it. Nothing in .github/, scripts/, or the justfile mentioned prefetch-npm-deps. The repair was folklore, which is why it recurred rather than got handled.

What this adds

A workflow that recomputes the hash on any PR touching the lockfile and commits it to the branch.

It is deliberately separate from the VS Code Extension (Nix) job. That job verifies; this one repairs. A verifier that silently rewrites the thing it is checking is worse than one that fails.

It handles forks. It cannot push to a fork branch, so it always writes the correct value to the job summary regardless:

npmDepsHash is stale

packages/vscode/package-lock.json changed, so flake.nix needs:

npmDepsHash = "sha256-…";

A contributor whose PR it cannot fix still gets the exact line to change, instead of a bare Nix hash mismatch.

The push is self-terminating. It only commits when the computed hash differs, so the run that push triggers finds a match and stops. No loop.

A local recipe, just nix-refresh-vscode-hash, plus a CONTRIBUTING section explaining why the failure happens at all.

Verification

I verified the command before writing a workflow around it, and verified the recipe both ways rather than only the happy path:

on main (hash correct):     ✓ npmDepsHash is already correct (sha256-Oc3yvM…)
after corrupting flake.nix: ✓ npmDepsHash sha256-AAAA… -> sha256-Oc3yvM…
                            ✓ flake.nix restored byte-identically

A repair tool that only ever reports "already correct" would be indistinguishable from one that does nothing.

Note

This does not fix #2269 or #2272 themselves — they were opened before the workflow existed. Once this merges, closing and reopening them (or any rerun) will pick it up. Worth knowing that they interfere: each changes the lockfile, so whichever merges first invalidates the other's hash, and the second needs a fresh run.

`flake.nix` pins `npmDepsHash` over packages/vscode/package-lock.json,
because buildNpmPackage hashes the vendored dependency tree. Dependabot
updates the lockfile and has no way to know a Nix expression hashes it,
so every npm bump to that package landed red on a fixed-output mismatch
and sat there until somebody recomputed the hash by hand. That is #2109,
#2202 and #2243, and both currently open dependabot PRs (#2269, #2272).
`build` requires that job, so none of them could ever merge unattended.

There was no tooling for it: nothing in .github, scripts or the justfile
mentioned prefetch-npm-deps. The repair was folklore.

Adds a workflow that recomputes the hash on any pull request touching the
lockfile and commits it to the branch. It is deliberately separate from
the `VS Code Extension (Nix)` job: that job verifies, this one repairs,
and a verifier that silently rewrites what it is checking is worse than
one that fails.

It cannot push to a fork, so it always writes the correct value to the
job summary as well. A contributor whose PR it cannot fix still gets the
exact line to change instead of a bare Nix hash mismatch.

The push is self-terminating: it only commits when the computed hash
differs, so the run it triggers finds a match and stops.

Also adds `just nix-refresh-vscode-hash` for the same repair locally, and
documents both in CONTRIBUTING.

Verified rather than assumed: the recipe reports "already correct" on
main, and when flake.nix is corrupted it repairs the value and restores
the file byte-identically.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Copilot AI lite review requested due to automatic review settings September 8, 2026 14:01
@robcohen
robcohen requested a review from a team as a code owner September 8, 2026 14:01
Comment on lines +38 to +45
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Check out the PR branch itself rather than the merge commit, so a
# push goes back to the contributor's branch.
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}

- uses: cachix/install-nix-action@13d8dd58da0234aa297dedd986986ccb8e7f3e24 # v31.11.1
@robcohen

robcohen commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

Superseded by #2284. The branch used a ci/ prefix, which the branch-name gate rejects; same commit on a chore/ branch.

@robcohen robcohen closed this Sep 8, 2026
@robcohen
robcohen deleted the ci/automate-vscode-npm-deps-hash branch September 8, 2026 14:03
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new local recipe is not portable to macOS due to sed -i usage and both the recipe/workflow suppress stderr, making failures unnecessarily hard to diagnose.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds automation and developer tooling to keep flake.nix’s pinned npmDepsHash synchronized with packages/vscode/package-lock.json, preventing routine VS Code extension dependency bumps (notably Dependabot PRs) from failing Nix builds due to fixed-output hash mismatches.

Changes:

  • Adds a dedicated GitHub Actions workflow that recomputes npmDepsHash on relevant PRs and pushes an updated flake.nix when possible (or reports the correct value in the job summary for forks).
  • Adds a local just nix-refresh-vscode-hash recipe to refresh the pinned hash manually.
  • Documents the workflow and manual fix procedure in CONTRIBUTING.md.
File summaries
File Description
justfile Adds a local just recipe to recompute and rewrite npmDepsHash in flake.nix.
CONTRIBUTING.md Documents why npmDepsHash goes stale and how CI/manual repair works.
.github/workflows/vscode-npm-deps-hash.yml New workflow to recompute and (when allowed) commit refreshed npmDepsHash back to PR branches.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +54 to +55
computed=$(nix shell nixpkgs#prefetch-npm-deps \
-c prefetch-npm-deps packages/vscode/package-lock.json 2>/dev/null | tail -1)
Comment thread justfile
Comment on lines +358 to +363
computed=$(nix shell nixpkgs#prefetch-npm-deps \
-c prefetch-npm-deps packages/vscode/package-lock.json 2>/dev/null | tail -1)
case "$computed" in
sha256-*) ;;
*) echo "prefetch-npm-deps produced no hash: '$computed'" >&2; exit 1 ;;
esac
Comment thread justfile
Comment on lines +369 to +370
sed -i "s|npmDepsHash = \"[^\"]*\"|npmDepsHash = \"$computed\"|" flake.nix
grep -q "npmDepsHash = \"$computed\"" flake.nix
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 99% (raw 93%, 169 masked)
Full AST Match 100%
Total Files 812
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants