Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: better error message for building fetchurl/fetchTarball when wrong hash is given #1905

Closed
dtzWill opened this issue Feb 25, 2018 · 2 comments

Comments

@dtzWill
Copy link
Member

dtzWill commented Feb 25, 2018

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.

dtzWill added a commit to dtzWill/nix that referenced this issue Mar 22, 2018
@domenkozar
Copy link
Member

For those that end up here, to calculate hash: nix-prefetch-url --unpack url

edolstra pushed a commit that referenced this issue Jun 20, 2018
@JohnAZoidberg
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants