Repository navigation
prefetch-npm-deps: add cacheVersion for packument support - #470517
Conversation
|
Okay. Looks like the error came back. |
|
now it works. Tested in numtide/llm-agents.nix#1364 |
|
This issue that is fixed by this PR: |
until NixOS/nixpkgs#470517 gets some merged.
|
cc @K900 @philiptaron @SuperSandro2000 @balsoft who do node stuff more regulary. |
|
Working through this now, there are some issues with the version of npm included in Node 24 I'm trying to work through myself before passing it off :P |
Add a cacheVersion parameter to fetchNpmDeps and npmDepsCacheVersion to buildNpmPackage. When set to 2, prefetch-npm-deps will also fetch and cache packuments (package metadata) in addition to tarballs. npm can request packuments with two different Accept headers: - corgiDoc: abbreviated metadata (default) - fullDoc: full metadata (used for workspaces) npm's cache policy requires headers to match, so we cache both versions. This is opt-in via cacheVersion to avoid breaking existing hashes. Set npmDepsCacheVersion = 2 for projects using npm workspaces. Also fix cacache index format to properly separate multiple entries with newlines, and update map_cache() to parse multi-line index files.
Document the new npmDepsCacheVersion option that enables packument caching for npm workspaces support.
d1f1c70 to
d028ea9
Compare
Fixed-output derivations for npm dependencies fail with hash mismatches when rebuilt on different days. The root cause is that npm registry metadata (packuments) contain volatile fields that change whenever upstream publishes a new version. For example, the TypeScript packument changes daily due to nightly releases, even though the lockfile pins a specific version. The cached packument includes _rev, time, modified, and the full versions list - all of which drift over time. Strip these volatile fields and filter the versions map to only include versions actually referenced in the lockfile. Signed-off-by: Jörg Thalheim <[email protected]>
|
Found & fixed another reproducibility issue. The new URLs would add new versions into the cache when those are uploaded to NPM. Now it only includes the version that are actually needed by the build. If we want to be sure, we can also wait for a couple of days to make sure there are not more issues. I have 8 packages now with this fetcher version on 3 different platforms that are up-dated every 1-2 days with ~1000 unique users. |
|
Is it possible to exclude the FODs from your cache so we can make sure that the reproducibility is sane by having all of the users build it? |
There are not included in the cache. The final package is though. Based on past experience there are plenty users that do not use the cache as for most packages the build time is not that high. The ci that updates hashes doesn't write to cache and the second one that verify the build will reproduce - this works ensures fod hashes that are generally not reproducible, it also catched Plattform-depending hashes in the past. Now the only thing that this doesn't help with is if the api doesn't give us immutable data over time. |
|
Looks like there are more volatile fields in this api response. The readme field seems to return sometimes content and sometimes not. Now i am considering whitelisting fields, which i think will also make it more robust, if the npm api gets extended in the future. |
|
I am now testing this variant: numtide/llm-agents.nix#1754 This now has the only fields I could find in npm install. Does our fetcher also needs to work with other package manager that I would need to check? |
Switch from stripping known volatile fields to using an explicit whitelist of allowed fields. This is more robust against upstream changes that add new fields which could affect hash stability. Top-level: only name and versions (dist-tags and time not needed for lockfile installs where versions are already resolved) Version-level: identity, all dependency types, dist, bin, platform constraints (engines/os/cpu), scripts, and deprecated flag. Based on analysis of pacote, npm-pick-manifest, npm-install-checks, and arborist - only fields actually read during npm install are included.
|
Seems to be overall more robust now. No reported issues anymore. |
|
Still no more issues since a week. |
| /// | ||
| /// npm's cache policy checks that the Accept header matches between the cached | ||
| /// request and the new request. npm can request packuments with two different headers: | ||
| /// 1. "corgiDoc" (abbreviated metadata) - used initially |
|
@Mic92, this is deployed to https://github.com/numtide/llm-agents.nix, right? |
|
I found one more field that is mutable unfortunately. Follow-up fix here: #481866 |
Use the correct attribute names after the cacheVersion -> fetcherVersion rename and mention fetchNpmDeps's fetcherVersion parameter as well. Addresses review feedback from NixOS#470517.
Use the correct attribute names after the cacheVersion -> fetcherVersion rename and mention fetchNpmDeps's fetcherVersion parameter as well. Addresses review feedback from #470517.
|
Do you think this would be acceptable to backport to 25.11? We have several security updates in a package that do not build without the new fetcher version. |
Add a cacheVersion parameter to fetchNpmDeps and npmDepsCacheVersion to buildNpmPackage. When set to 2, prefetch-npm-deps will also fetch and cache packuments (package metadata) in addition to tarballs.
npm can request packuments with two different Accept headers:
npm's cache policy requires headers to match, so we cache both versions.
This is opt-in via cacheVersion to avoid breaking existing hashes. Set npmDepsCacheVersion = 2 for projects using npm workspaces.
Also fix cacache index format to properly separate multiple entries with newlines, and update map_cache() to parse multi-line index files.
This change allows me to build qwen-code.
Fixes #474535
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.