Repository navigation
Description
Nixpkgs version
- Stable (25.11)
Describe the bug
I have a custom package that uses pnpm. When building locally (Nix 2.31.2), everything works fine.
However, when building on GitHub Actions, the hash for pnpmDeps frequently has a mismatch with the expected one. Sometimes retrying the run fixes the problem, but not always. Interestingly, the hash it gets is not always the same:
error: hash mismatch in fixed-output derivation '/nix/store/q745430xvhjpy9y4bbs2p7p8w0nhy61j-book-metadata-api-pnpm-deps.drv':
specified: sha256-isco9zsgbzfG+nHvEXNiGoRaDxeRhIYzmrNsrw9oyec=
got: sha256-1OeZzKfzzzabCXI2nsKp1SRFz4rzEFuDb6y6vP4r6O4=
error: hash mismatch in fixed-output derivation '/nix/store/q745430xvhjpy9y4bbs2p7p8w0nhy61j-book-metadata-api-pnpm-deps.drv':
specified: sha256-isco9zsgbzfG+nHvEXNiGoRaDxeRhIYzmrNsrw9oyec=
got: sha256-wXLu8I50lYzJKvnZn/fS+5+prVUYDszTvBGBwPAXRUw=
Both of these runs appear to be using Nix 2.33.0.
These actions are run against commit diogotcorreia/dotfiles@7766271
Note: It also doesn't appear to be isolated to that specific package. While packaging discord-nordic, the same thing has happened:
https://github.com/diogotcorreia/dotfiles/actions/runs/21335933059/job/61407831799 (commit diogotcorreia/dotfiles@e0c05f5)
error: hash mismatch in fixed-output derivation '/nix/store/z4wdabmbncnkmrw1i0rgfdcf1ryg7zw4-discord-nordic-pnpm-deps.drv':
specified: sha256-oCdJNX/bft8OFNw+KbizfsDgY03iTcISEjqshJNcZWQ=
got: sha256-RAHLq+MhvTbofoPqWGBOAM/vhk1+7zlfldo42Spzi/k=
Re-running the build again succeeded.
Steps to reproduce
I'm not sure how exactly to reproduce this, since it doesn't appear to happen on my machine.
My dotfiles contain a flake, so that part should be easy to reproduce, by running nix build .#book-metadata-api.pnpmDeps -L.
I'll update this section if I find anything else.
Expected behaviour
The hash should always match
Screenshots
No response
Relevant log output
Additional context
I'll be happy to help with debugging, just let me know what you need from my side.
Relates to: #469950
System metadata
Unfortunately can't run this on GitHub Actions
Notify maintainers
Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)
I assert that this issue is relevant for Nixpkgs
- I assert that this is a bug and not a support request.
- I assert that this is not a duplicate of an existing issue.
- I assert that I have read the NixOS Code of Conduct and agree to abide by it.
Is this issue important to you?
Add a 👍 reaction to issues you find important.
Activity
[-]fetchPnpmDeps: fetcherVersion 3 hash is not consistent on github action runners[/-][+]fetchPnpmDeps: fetcherVersion 3 hash is not consistent on github actions runners[/+]gepbird commentedon Jan 26, 2026
Thanks for the report! I'll try to reproduce it later when I'll have more time.
To debug GHA, I found the
owenthereal/action-upterm@v1action useful that opens an SSH session on the runner's machine where you can execute commands. Can you check how does thebook-metadata-api.pnpmDepsartifact look like on the runner, how does it differ from the one that you build on your machine? Maybe getting the system metadata there could be also helpful.diogotcorreia commentedon Jan 27, 2026
@gepbird I tried building the packages in GHA just by themselves and it succeeded, so my guess now is that it happens when the system is under stress. Will keep trying to reproduce.
Regardless, do you know of a way to get the contents of
$outright before the build fails due to hash mismatch? I know--keep-failedexists, but that doesn't seem to leave$outanywhere.And:
gepbird commentedon Jan 28, 2026
You could try running the
stressCLI tool to simulate max CPU usage for example.Maybe there's a better way for what you're asking specifically, but adding
breakpointHooktonativeBuildInputsis nice for debugging. Similarly to how theowenthereal/action-uptermaction gives you SSH access and a shell into the runner,breakpointHookgives you a shell inside the Nix build sandbox. You have access to variables like$outfor the final result, and you get dropped into IIRC/buildwhich is where$srcis usually unpacked and most commands usually act on the files inside this directory. You can inspect the files, but if you need additional tools you should add them tonativeBuildInputsfor the derivation. ForfetchPnpmDepsyou probably want to add this here:nixpkgs/pkgs/build-support/node/fetch-pnpm-deps/default.nix
Lines 70 to 78 in 000f309
That's a bit more finicky, for that to work I think you need to add a
nixpkgschannel withnix-channel, but I haven't used that in a while. You should get the same result withnix run nixpkgs#nix-info -- -m.gepbird commentedon Jan 28, 2026
I'm currently trying to reproduce it.
I can't check this out locally after cloning the repo, I'll try diogotcorreia/dotfiles@e0c05f5 instead with
discord-nordispackage as you said this is affected too.discord-nordicwas built on GHA:In an upterm session I also tried
nix run nixpkgs#stress -- --cpu 4then rebuildingdiscord-nordic.pnpmDepsa few times, I couldn't reproduce the issue. In case you want to get the same environment as me, I was doing this on https://github.com/gepbird/diogotcorreia-dotfiles/tree/pnpm-repro-attempt.Maybe it's worth trying out older
fetcherVersions, but I don't think that's related.Let me know if you can find a consistent reproducer.
(I wonder if it was network related, for example the npm registry was silently misbehaving?)
diogotcorreia commentedon Jan 29, 2026
Thank you for your efforts!
Unfortunately this doesn't seem to work for hash mismatches, only for build failures.
Yeah, the commit I mentioned was from a PR, so it isn't available anymore 😅 The equivalent commit is diogotcorreia/dotfiles@c5e3bfa
That would be concerning, but certainly a possibility.
I have also tried to reproduce it again, this time by running the full host rebuild but setting the pnpmDeps
hashto"", and the build failed with an unexpected hash: https://github.com/diogotcorreia/dotfiles/actions/runs/21461507746/job/61814834469Weirdly enough, I couldn't reproduce this when disabling the cache, so that might be involved.
With the debug I added, the failure created an artifact with the (incorrectly) built
pnpmDepspackage: https://github.com/diogotcorreia/dotfiles/actions/runs/21461507746/artifacts/5297028020First thing I could notice is that the checksum of
pnpm-store.tar.zstis different (obviously):Using
diff -r, it seems like a bunch of index dirs are missing (/tmp/pnpm-storeis the expected store,./Unpack-9914is from GHA):Weirdly enough, these appear to be a subset of the empty index directories:
I'm really not sure what is going on here 😅 But I can investigate further tomorrow now that we have a bit more information.
diogotcorreia commentedon Jan 29, 2026
More insights:
stress, it doesn't seem to make the build failnothing-but-nixdoesn't delete anything, so could certainly be btrfs-releatedI'll look a bit further into the btrfs configuration and see if anything odd stands out.
diogotcorreia commentedon Jan 29, 2026
I had no luck with btrfs, so I started looking into pnpm and I think I found some sort of race condition (?)
So, pnpm (v10.28.0) creates all the directories here: https://github.com/pnpm/pnpm/blob/v10.28.0/worker/src/start.ts#L197-L215
However, if any of the
fs.mkdirSynccalls fail, it stops creating the remaining directories as well. To test this theory, I patched pnpm (btw, why are we getting it from npm instead of building from source?ugh, seems like you'd need pnpm to build pnpm 🙃) and added some debug logs, which gave me this log on GHA:This appears to happen because another part of the program has already started adding things into the files/index directories before
initStorefinishes (perhaps due to high I/O load?). While testing this locally,init-storeis finished before any other message is handled, so the hash of the derivation is correct.An easy fix in nixpkgs would be to create all the missing directories before creating the tarball, but perhaps this should also be reported upstream? What do you think?
gepbird commentedon Jan 30, 2026
Thanks for all of your research, I haven't dug much deeper into this than my last comment, some things that come to my mind:
Maybe running
stress --io(or run it with--hdd/--hdd-bytes?) makes it more reproducible, even locally. Using a slower IO device could also help, you can specify another nix store, for examplenix build --store /path/to/slow/io/dir .#book-metadata-api.pnpmDeps. I may try this later on my ancient HDD that even requires a power cable and currently it's just collecting dust :DWhat do you mean by this exactly? If I understand correctly, the pnpm commands create those directories, how can we know which directories to create in advance? If we create
aa,ab, ...,ff, seems like it can waste a small amount of storage, and would require introducing afetcherVersion = 4.From the above error it could be a race condition, maybe thread 1 tries to
stata path, which results in not found, thread 2stats with not found, thread 1mkdirs which is success, thread 2mkdirs which fails. In this case we should probably report it to upstream.diogotcorreia commentedon Jan 30, 2026
I can try checking if there is a way to simulate slow I/O on Linux. But I did try
stresswith--ioand--hdd/--hdd-bytesin the GHA VM yesterday without success.Another option would be to purposely add sleeps to the pnpm code to demonstrate the race condition, but I'd prefer if it were reproducible without patching pnpm.
No,
pnpmalways (well, when it doesn't encounter this race condition) creates the fullaa, ..,ff, regardless if the directories are going to be empty or not. I think it is safe to assume all existingpnpmHashes in nixpkgs have the correct structure already, so we wouldn't need a newfetcherVersionas it would be a no-op in all existing cases.For example, this is a possible fix on our side:
I'll hold off creating a PR for now, given we can probably get a fix upstream instead.
I don't think that's the problem here, the code is designed to just blindly
mkdir, it doesn't check if the dir already exists, just catches/ignores the error, which exits from the loop before all dirs are created.I'll report it upstream then! A PR there shouldn't be too difficult.
diogotcorreia commentedon Jan 30, 2026
I have managed to create a setup that reproduces this on my laptop:
(courtesy of https://serverfault.com/questions/523509/linux-how-to-simulate-hard-disk-latency-i-want-to-increase-iowait-value-withou)
It uses
dm-mapperto create an artificial delay of writes/reads, and, more importantly, mounts with-o dirsyncto delay calls tomkdir.Make sure to run it without root, unless you are running nix with root as well.
There are more detailed instructions in the upstream issue: pnpm/pnpm#10535
Let me know if this works for you as well.
diogotcorreia commentedon Jan 31, 2026
The fix upstream has been merged, let's hope it gets backported to pnpm v10 soon: pnpm/pnpm#10536
gepbird commentedon Jan 31, 2026
Huge thanks for reaching out to them and fixing it! Yea, let's hope it will be in the next v10 release :)
I don't want to force extra work on you, only if you are interested in improving pnpm inside nixpkgs and have the time.
pnpm/pnpm#5315 is blocking us from using
pnpm deploy. I admit I haven't done a lot of research on it, but if my understanding is correct it should improve packaging by a lot.Currently some Nix packages built with pnpm ship many megabytes or even gigabytes of
node_moduleswhich are mostly unnecessary. Not shippingnode_moduleswill make some/most packages not work at all, because there are references to that in the built e.g.distfolder.pnpm deployshould reduce this and we could get rid ofpnpm pruneand hacky manual cleanups that try to remove some of the unnecessary files.nixpkgs/pkgs/by-name/n8/n8n/package.nix
Lines 63 to 84 in dc98539
diogotcorreia commentedon Feb 18, 2026
@gepbird Thanks for letting me know. I still haven't had the time, but if I do I'll be happy to look into it.
The fix for this issue has been released in 10.29.0 a few weeks ago.
pnpm/pnpm@v10.28.2...v10.29.0
Will be fixed in nixpkgs once #488068 is merged.