Nix: fetchurl and builtins.fetchTarball disagree on the SHA256 of fetched file

Created on 13 May 2019  路  2Comments  路  Source: NixOS/nix

To reproduce this, try the following in nix repl <nixpkgs>

fetchurl { url=https://crates.io/api/v1/crates/arrayvec/0.4.10/download;sha256="92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"; }

versus

fetchTarball {url=https://crates.io/api/v1/crates/arrayvec/0.4.10/download;sha256="92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71";}

fetchurl gets a SHA256 that is consistent with the hash of the actual file, but fetchTarball does not.

Most helpful comment

This is normal, if you look at the result of both builds you'll see that they are different. fetchurl just downloads a file while fetchTarball downloads and unpacks it first, in which case the unpacked content is hashed.

The different hashing modes are described in a bit more detail herehttps://nixos.org/nix/manual/#fixed-output-drvs.

All 2 comments

This is normal, if you look at the result of both builds you'll see that they are different. fetchurl just downloads a file while fetchTarball downloads and unpacks it first, in which case the unpacked content is hashed.

The different hashing modes are described in a bit more detail herehttps://nixos.org/nix/manual/#fixed-output-drvs.

You can get the "unpacked" hash using nix-prefetch-url --unpack BTW.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dasJ picture dasJ  路  3Comments

bryanhuntesl picture bryanhuntesl  路  3Comments

ihsanturk picture ihsanturk  路  3Comments

bflyblue picture bflyblue  路  3Comments

ericsagnes picture ericsagnes  路  4Comments