FetchFromGitHub hash mismatch hashes truncated in error message

I’m developing a nix package for a little project of mine, and using fetchFromGitHub to obtain the project source. However, I’m trying to determine the sha256 to use for it, and am confused.

Until recently, I’d put in a temp/filler hash, and the error message from the builder would show me the hash I need to use. However, I did this again yesterday and find the error message now has truncated hashes in it. I’m a little perplexed!

What I see now is:

unpacking source archive /build/4a247368e0ddcea8f89e21bc80b8fcb0ae275d3c.tar.gz
error: hash mismatch in fixed-output derivation '/nix/store/lncz2pk595vqck2dcr9smd760dy6fm9m-source.drv':
         specified: sha256-YZCbrFonGwaFNelzINg/dSThl4GbjB2gNQqPA1ti26o=
            got:    sha256-gOAFRMUuje85jTdQ4glHZPdocUg010mYQ5iCGTXjcLM=

So:

  1. When/why/(how!) did this message format change to be truncated, and
  2. How does one get access to this hash now?

Of course, this method always felt like a hack, but I’ve never been able to figure out another way. Perhaps there’s an official tool now?

I did this again yesterday and find the error message now has truncated hashes in it. I’m a little perplexed!

Are you talking about format? These are all the same hash, just encoded differently:

61909bac5a271b068535e97320d83f7524e197819b8c1da0350a8f035b62dbaa # 16 bit
1anvc9dh73qa6nh1v34vh6by293m7zc20wz96n2hc6r7ban9p431 # 32 bit encoding
YZCbrFonGwaFNelzINg/dSThl4GbjB2gNQqPA1ti26o= # 64 bit encoding
sha256-YZCbrFonGwaFNelzINg/dSThl4GbjB2gNQqPA1ti26o= # 64 bit encoding + hash algo (sri format)

When/why/(how!) did this message format change to be truncated, and

2.3 had 32bit encoded string by default, 2.4+ uses sri

How does one get access to this hash now?

In nix>2.4, you can do nix hash to compute the other encodings

If you’re talking about the sha becoming stale, This was the motivating factor behind [staging] fetchFromGitHub: name source with content intristic to the value by jonringer · Pull Request #153386 · NixOS/nixpkgs · GitHub

4 Likes

Wow, thanks for the incredibly informative reply! The sri format works perfectly. :slight_smile:

1 Like