[Nix-dev] nix-prefetch-url and sha256sum differs

Bjørn Forsman bjorn.forsman at gmail.com
Mon Apr 1 10:42:08 CEST 2013


On 1 April 2013 10:19, Marc Weber <marco-oweber at gmx.de> wrote:
>> When I run sha256sum on the downloaded file I get the correct result:
> nix-hash --type sha256 [--flat] file
>
> I don't know why the output differs  from the sha256sum tool.

$ nix-hash --type sha256
/nix/store/6alqcyg5qayvwv90vqay1kqxq40mqmm0-lighttpd-1.4.32.tar.gz
9095cdc75e33d80f2c3e076b2fce1a2aac5b5b090cacbbe035bce09be80108ee

$ nix-hash --type sha256 --flat
/nix/store/6alqcyg5qayvwv90vqay1kqxq40mqmm0-lighttpd-1.4.32.tar.gz
0765e07dac432393dea3950639d5ba646ded95a9408ad002e54b3353ab6b9645

$ sha256sum /nix/store/6alqcyg5qayvwv90vqay1kqxq40mqmm0-lighttpd-1.4.32.tar.gz
0765e07dac432393dea3950639d5ba646ded95a9408ad002e54b3353ab6b9645
/nix/store/6alqcyg5qayvwv90vqay1kqxq40mqmm0-lighttpd-1.4.32.tar.gz

So the --flat argument must be passed for it to behave like sha256sum.

[Reading man nix-hash]

"The hash is computed over a serialisation of each path: a dump of the
file system tree rooted at the path. This allows directories and
symlinks to be hashed as well as regular files. The dump is in the NAR
format produced by nix-store --dump. Thus, nix-hash path yields the
same cryptographic hash as nix-store --dump path | md5sum."

So now I'm thinking that nix-prefetch-url does the same, i.e. hashes
the "serialisation" of the path. But no, it doesn't behave like
nix-hash, neither with or without --flat:

$ nix-prefetch-url --type sha256
http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.32.tar.gz
[...]
path is ‘/nix/store/6alqcyg5qayvwv90vqay1kqxq40mqmm0-lighttpd-1.4.32.tar.gz’
0icndfmm6csbwl1d12j0m6aysvb4pbakj1lmlgg968s3miyy0r87

$ nix-hash --type sha256
/nix/store/6alqcyg5qayvwv90vqay1kqxq40mqmm0-lighttpd-1.4.32.tar.gz
9095cdc75e33d80f2c3e076b2fce1a2aac5b5b090cacbbe035bce09be80108ee

$ nix-hash --type sha256 --flat
/nix/store/6alqcyg5qayvwv90vqay1kqxq40mqmm0-lighttpd-1.4.32.tar.gz
0765e07dac432393dea3950639d5ba646ded95a9408ad002e54b3353ab6b9645

Best regards,
Bjørn Forsman


More information about the nix-dev mailing list