Skip to content

fix: fix NAR hash verification to use nix-hash for nix32 conversion - #1101

Merged
kalbasit merged 2 commits into
mainfrom
feat-add-nar-hash-verification
Mar 17, 2026
Merged

kalbasit merged 2 commits into
mainfrom
feat-add-nar-hash-verification

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

The script now properly converts Nix SRI hashes (sha256:nix32hash) to hex
using nix-hash instead of incorrectly treating the nix32 string as hex.
This fixes hash verification for both compressed and uncompressed NARs.

Additionally, verification is now done per-host with results displayed in a
column. If verification fails, a secondary table shows expected vs actual
hashes for each failed host.

The script now properly converts Nix SRI hashes (sha256:nix32hash) to hex
using nix-hash instead of incorrectly treating the nix32 string as hex.
This fixes hash verification for both compressed and uncompressed NARs.

Additionally, verification is now done per-host with results displayed in a
column. If verification fails, a secondary table shows expected vs actual
hashes for each failed host.
@kalbasit

kalbasit commented Mar 17, 2026 •

Copy link
Copy Markdown
Owner Author

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 17, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the ttfb.py script by improving the accuracy and diagnostic capabilities of NAR hash verification. The changes ensure that Nix SRI hashes are correctly processed and provide clearer, more detailed feedback on verification outcomes across multiple hosts, making the script more robust for testing and debugging.

Highlights

  • NAR Hash Verification Fix: Corrected the NAR hash verification logic to properly convert Nix SRI hashes (sha256:nix32hash) to hexadecimal using the nix-hash utility, resolving issues with both compressed and uncompressed NARs.
  • Per-Host Verification and Reporting: Implemented per-host hash verification with results displayed in a dedicated column. If verification fails for any host, a secondary table is presented showing the expected versus actual hashes for detailed debugging.
  • New CLI Argument: Added a --no-verify command-line argument to the ttfb.py script, allowing users to optionally skip NAR hash verification.
Changelog
  • dev-scripts/run.py
    • Fixed a typo in a variable name (enabled_lazy_cdc to enable_lazy_cdc) when configuring CDC lazy chunking.
  • dev-scripts/ttfb.py
    • Added hashlib and subprocess imports for hash computation and nix-hash execution.
    • Introduced nix_hash_to_hex function to convert Nix SRI hashes (nix32 or hex) to standard hexadecimal format using nix-hash.
    • Implemented parse_narinfo function to extract key-value pairs from narinfo text.
    • Added get_expected_hash_info function to determine the appropriate hash (NarHash or FileHash) from narinfo based on compression status.
    • Created verify_nar_hash asynchronous function to download NARs, compute their SHA256 hash, and compare it against the expected hash from narinfo.
    • Refactored fetch_metrics into fetch_with_verification to include narinfo and do_verify parameters, enabling optional hash checking.
    • Modified fetch_with_verification to accumulate downloaded content for hash calculation and updated its return structure to include hash verification results.
    • Added a --no-verify command-line argument to allow skipping hash verification.
    • Updated the main function to parse narinfo using the new parse_narinfo function, determine verification status, and pass relevant data to fetch_with_verification.
    • Enhanced result reporting in the main function to include a 'Hash' column for verification status and a detailed table for failed hash comparisons.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@dosubot dosubot Bot added the bug Something isn't working label Mar 17, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request correctly implements NAR hash verification by using nix-hash for nix32 to hex conversion in the ttfb.py script. The script's output is also improved to show verification results per host.

My review focuses on improving the performance and robustness of the new verification logic. I've identified a performance issue where the NAR content is downloaded twice and suggested a refactoring to avoid this. I've also suggested an improvement to the error handling when the nix-hash command is not available to provide clearer feedback to the user.

Comment thread dev-scripts/ttfb.py Resolved
Comment thread dev-scripts/ttfb.py Resolved
Comment thread dev-scripts/ttfb.py Resolved
@codecov

codecov Bot commented Mar 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.04%. Comparing base (7924c85) to head (5d1513c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1101   +/-   ##
=====================================
  Coverage   5.04%   5.04%           
=====================================
  Files          6       6           
  Lines        436     436           
=====================================
  Hits          22      22           
  Misses       410     410           
  Partials       4       4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalbasit
kalbasit enabled auto-merge (squash) March 17, 2026 06:57
@kalbasit
kalbasit merged commit ae0e6cb into main Mar 17, 2026
21 of 28 checks passed
@kalbasit
kalbasit deleted the feat-add-nar-hash-verification branch March 17, 2026 07:08
kalbasit added a commit that referenced this pull request Jun 8, 2026
## Summary

The `[Unreleased]` section was populated in #1309 but skewed toward the
recent CDC-drain, in-flight-staging, and Ent-migration work, omitting
several user-facing features and fixes that also landed since v0.9.4.
This backfills the missing notable changes, each cross-referenced by PR.

**Added**
- `ncps fsck` command + Helm fsck CronJob (#975, #996, #998, #999,
#1000, #1004, #1006, #1176)
- Closure pinning HTTP endpoints `POST`/`DELETE /pin/{hash}.narinfo`,
`GET /pins` (#1108)
- pprof server via `--pprof-addr` (#1063)
- CDC lazy chunking as a feature + `--cache-cdc-lazy-cleanup-schedule` +
recovery cron (#1082, #1083, #1089, #1096)
- Helm: auto `GOMEMLIMIT` (#1061), configurable temp volume /
`volumeClaimTemplate` (#1074, #1077), SQLite `Recreate` strategy (#1012)
- Startup storage reporting + deprecated-narinfo warning (#959, #961)
- `docker-dev` image (#1097)

**Fixed**
- `store/tmp` no longer wiped on startup (#1313)
- `nix-hash` NAR verification (#1101)
- Prometheus counters primed at startup (#1337, #1343)
- 404 on un-reassemblable chunked NARs (#1319), purged narinfo no longer
500 (#1318), fail-fast tmp validation (#1086)
- Further CDC/cache reliability fixes (#1317, #1346, #1341, #1342,
#1331, #1347)

**Changed**
- CDC config now persisted in the DB config table (#971)

Dependency bumps, CI/test-only changes, and the internal Ent-conversion
PRs are intentionally excluded; the existing Ent-migration entry already
covers that work.

## Test plan

- [x] `nix fmt` reports no changes (docs-only edit)
- [x] CHANGELOG section structure intact
(Added/Fixed/Changed/Removed/Migration/CI)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant