Currently when using fetchTarball or fetchurl builtins with the sha256 specified, the resulting error message is a bit unclear:
$ nix eval '(fetchTarball { url = https://github.com/NixOS/nixpkgs/archive/566ded39b1c76ac512c65a14e6ab14751814a9b9.tar.gz; sha256 = "0j05khrlvjsj7aflv11by24k57gjncql5hkqihrh7q5s9snb221v"; })' --store $HOME/test-store
error: store path mismatch in file downloaded from 'https://github.com/NixOS/nixpkgs/archive/566ded39b1c76ac512c65a14e6ab14751814a9b9.tar.gz'
(FWIW, here's the invocation using the correct hash:
$ nix eval '(fetchTarball { url = https://github.com/NixOS/nixpkgs/archive/566ded39b1c76ac512c65a14e6ab14751814a9b9.tar.gz; sha256 = "0j05khrlvjsj7aflv11by24k57gjncql5hkqihrh7q5s9snb220v"; })' --store $HOME/test-store
)
If it's not too much trouble, I think ideally it would explain that the wrong hash was given, and ideally would print the "actual" hash computed.
It appears this happens with builtins.fetchurl as well.
Oh, and I'm use non-standard store above just as a way to ensure these paths don't exist already--same behavior with default/normal store.
For those that end up here, to calculate hash: nix-prefetch-url --unpack url
Is there documentation for when to use which kind of hash?
Many times nix-prefetch-url works but apparently here I need nix-prefetch-url --unpack url.
Previously I used nix-hash --type sha256 --flat --base32.
Most helpful comment
For those that end up here, to calculate hash:
nix-prefetch-url --unpack url