-
Notifications
You must be signed in to change notification settings - Fork 23
automatically update the nix vendor hash #1672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
this make task is run in pre-push hooks, so this should reduce CI churn because of out-of-sync nix vendor hashes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces automatic updating of the nix vendor hash to reduce CI failures. When the test-nix target (run in pre-push hooks) detects a nix build failure, it automatically updates the vendorHash in pkgs/defang/cli.nix and stages the change.
Key changes:
- Modified
test-nixto automatically update vendor hash on failure - Added
update-nix-vendor-hashtarget that manipulates vendorHash using sed - Extracted
nix-runas a separate reusable target
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
Co-authored-by: Lio李歐 <[email protected]>
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughTwo new Makefile targets are added: Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related issues
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
Makefile (1)
39-46: Hardenupdate-nix-vendor-hash: pipe failures, magic hash, and staging on errorThe overall flow is good, but this target is brittle in a few ways:
- The
nix-run | grep | tail | xargs sedpipeline ignores failures (noset -o pipefail), so ifgrepfinds nothing ornix-runfails differently, the recipe still progresses togit addwith an unchanged or invalid hash.- The placeholder
0AAAAAAAA…is a magic value with no explanation; it’s non-obvious why that particular string is used to force Nix to recompute the vendor hash.sed -i.bakis run twice, both times writing the same.bakfile, which is then removed once. That works, but it’s a bit confusing and masks which step actually changed the file.These issues can cause
cli.nixto be staged with a still-broken vendorHash and leave the developer in a confusing state.Consider tightening this target along these lines:
.PHONY: update-nix-vendor-hash update-nix-vendor-hash: - sed -i.bak -E 's|(vendorHash = "sha256-)[A-Za-z0-9+/=]+(")|\10AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\2|' pkgs/defang/cli.nix - $(MAKE) nix-run 2>&1 | grep -o 'sha256-[A-Za-z0-9+/=]\+' | tail -n1 | xargs -I {} sed -i.bak -E 's|(vendorHash = ")[^"]+(")|vendorHash = "{}"|' pkgs/defang/cli.nix - rm pkgs/defang/cli.nix.bak - git add pkgs/defang/cli.nix - @echo cli.nix vendorHash has been updated; commit and push - @false + @bash -euo pipefail -c '\ + # Force a vendorHash mismatch so Nix prints the expected one. Magic value: 44 "A"s. \ + sed -i .bak1 -E "s|(vendorHash = \"sha256-)[A-Za-z0-9+/=]+(\")|\1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\2|" pkgs/defang/cli.nix; \ + nix run .#defang-cli --extra-experimental-features flakes --extra-experimental-features nix-command 2>&1 \ + | grep -o "sha256-[A-Za-z0-9+/=]\+" | tail -n1 \ + | xargs -r -I {} sed -i .bak2 -E "s|(vendorHash = \")[^\"]+(\" )|vendorHash = \"{}\" \2|" pkgs/defang/cli.nix; \ + ' + @rm -f pkgs/defang/cli.nix.bak1 pkgs/defang/cli.nix.bak2 + git add pkgs/defang/cli.nix + @echo cli.nix vendorHash has been updated; commit and push + @falseKey points: explicit comment for the magic hash,
set -euo pipefailfor the pipeline, and only staging the file after a fully successful update.
🧹 Nitpick comments (1)
Makefile (1)
33-36: test-nix logic is correct; consider simplifying the shell flowThe conditional logic works as intended: only when
nix-runfails do we attemptupdate-nix-vendor-hash. You can simplify and avoid the manual$?check with a more idiomatic one-liner:-test-nix: -ifneq (,$(shell which nix)) - +$(MAKE) nix-run; \ - if [ $$? -ne 0 ]; then \ - $(MAKE) update-nix-vendor-hash; \ - fi -endif +test-nix: +ifneq (,$(shell which nix)) + +$(MAKE) nix-run || $(MAKE) update-nix-vendor-hash +endifThis keeps behavior the same while reducing shell boilerplate.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Makefile(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Analyze (go)
- GitHub Check: go-test
🔇 Additional comments (1)
Makefile (1)
48-50:nix-runtarget looks good and keeps the Nix invocation centralizedCentralizing the
nix runinvocation behindnix-runis clean and makes reuse easy from other targets. No issues from a Make/Nix perspective.
lionello
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway we can test this before merge?
this make task is run in pre-push hooks, so this should reduce CI churn because of out-of-sync nix vendor hashes
Description
Linked Issues
Checklist
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.