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

How to manually replicate/reproduce/obtain the sha256 hash specified in Nix with fetchgit or fetchFromGitHub? #1880

Open
hydramo opened this Issue Feb 19, 2018 · 6 comments

Comments

Projects
None yet
5 participants
@hydramo

hydramo commented Feb 19, 2018

At https://nixos.org/nixpkgs/manual/ we see this example:

src = fetchgit {
  url = "git://github.com/NixOS/nix.git";
  rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
  sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg";
}

src = fetchgit {
  url = "https://github.com/NixOS/nix.git";
  rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
  sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg";
}

src = fetchFromGitHub {
  owner = "NixOS";
  repo = "nix";
  rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
  sha256 = "04yri911rj9j19qqqn6m82266fl05pz98inasni0vxr1cf1gdgv9";
}

How do I obtain these hashes myself? I tried the commands

$ nix-prefetch-url https://github.com/NixOS/nix/archive/1f795f9f44607cc5bec70d1300150bfefcef2aae.tar.gz
downloading ‘https://github.com/NixOS/nix/archive/1f795f9f44607cc5bec70d1300150bfefcef2aae.tar.gz’... [13/589 KiB, 3.3 KiB/s]
path is ‘/nix/store/4hrp5jv1rv51lcwf097hbcjjksnwpwi6-1f795f9f44607cc5bec70d1300150bfefcef2aae.tar.gz’
1311maadkx2xq2ll9apfsyjq5gy5q874z4db7l2riz7vqpx1bxhs

$ nix-prefetch-url https://github.com/NixOS/nix/archive/1f795f9f44607cc5bec70d1300150bfefcef2aae.zip
downloading ‘https://github.com/NixOS/nix/archive/1f795f9f44607cc5bec70d1300150bfefcef2aae.zip’... [306/835 KiB, 146.0 KiB/s]
path is ‘/nix/store/gy1zkg71mrlpf5lh8ypl1kg8d2ps6m05-1f795f9f44607cc5bec70d1300150bfefcef2aae.zip’
1b3vnxfpidwpmgh9dlpmhvrrkkgn3a0r56bv175y6hzfhnx4s5kn

but as you can see, both hashes are completely different from any of the above two.

So how do I actually replicate/reproduce/obtain the sha256 hash specified in Nix with fetchgit or fetchFromGitHub?

@vcunat

This comment has been minimized.

Member

vcunat commented Feb 19, 2018

It's --unpack, as documented for nix-prefetch-url.

$ nix-prefetch-url --unpack https://github.com/NixOS/nix/archive/1f795f9f44607cc5bec70d1300150bfefcef2aae.tar.gz

unpacking...
path is '/nix/store/74r3qzg6slx4x9lc4v1yvrr7vzjqig3m-1f795f9f44607cc5bec70d1300150bfefcef2aae.tar.gz'
1i2yxndxb6yc9l6c99pypbd92lfq5aac4klq7y2v93c9qvx2cgpc

$ nix-prefetch-url --unpack https://github.com/NixOS/nix/archive/1f795f9f44607cc5bec70d1300150bfefcef2aae.zip
unpacking...
path is '/nix/store/560ws6c0pxr1g67hqpm7w490y1045l31-1f795f9f44607cc5bec70d1300150bfefcef2aae.zip'
1i2yxndxb6yc9l6c99pypbd92lfq5aac4klq7y2v93c9qvx2cgpc

The hash 04yri911rj9j19qqqn6m82266fl05pz98inasni0vxr1cf1gdgv9 is wrong. The fetchFromGitHub call above only works with the hash output above (tested now).

@hydramo

This comment has been minimized.

hydramo commented Feb 19, 2018

Your command is not matching the stuff in fetchFromGitHub. Here is a real example (as opposed to example hardcoded in docs): https://github.com/NixOS/nixpkgs/blob/a78a1d61b56405aeaf04c173e4e3eebbc7cc52b8/pkgs/applications/altcoins/bitcoin-unlimited.nix

If we look into https://github.com/bitcoinunlimited/bitcoinunlimited, we see that the tag v1.0.2.0 corresponds to commit 9fcdbf50585744696c74c162398cea4f026efda4.

If we try your command:

$ nix-prefetch-url --unpack https://github.com/bitcoinunlimited/bitcoinunlimited/archive/9fcdbf50585744696c74c162398cea4f026efda4.tar.gz
...
0v8gkjwl9ivqkq2gj03gsw4syirwnmgb2mrvix7700cnb3xghzbn

That's a totally different hash than that in the .nix file above.

Any ideas?

@vcunat

This comment has been minimized.

Member

vcunat commented Feb 19, 2018

You found another bad expression :-D

nix-build -E 'with import <nixpkgs> {}; 
                        fetchFromGitHub {
                            owner = "bitcoinunlimited";
                            repo = "bitcoinunlimited";
                            rev = "v1.0.2.0";
                            sha256 = "17cmy0s1908s2rqs0zwr05f3541nqm2pg08n2xn97g2k3yimdg5q";
                        }'
these derivations will be built:
  /nix/store/hp5hbwz4i9mqazxbcgk2kl7kxvmimqml-bitcoinunlimited-v1.0.2.0-src.drv
building path(s) ‘/nix/store/vliwfr87qw9rgmjxy6rfz0zcynazfv6z-bitcoinunlimited-v1.0.2.0-src’

trying https://github.com/bitcoinunlimited/bitcoinunlimited/archive/v1.0.2.0.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   143    0   143    0     0    143      0 --:--:-- --:--:-- --:--:--   255
100 6932k  100 6932k    0     0   173k      0  0:00:40  0:00:40 --:--:--  113k
unpacking source archive /tmp/nix-build-bitcoinunlimited-v1.0.2.0-src.drv-0/v1.0.2.0.tar.gz
output path ‘/nix/store/vliwfr87qw9rgmjxy6rfz0zcynazfv6z-bitcoinunlimited-v1.0.2.0-src’ has r:sha256 hash ‘0v8gkjwl9ivqkq2gj03gsw4syirwnmgb2mrvix7700cnb3xghzbn’ when ‘17cmy0s1908s2rqs0zwr05f3541nqm2pg08n2xn97g2k3yimdg5q’ was expected
error: build of ‘/nix/store/hp5hbwz4i9mqazxbcgk2kl7kxvmimqml-bitcoinunlimited-v1.0.2.0-src.drv’ failed
@vcunat

This comment has been minimized.

Member

vcunat commented Feb 19, 2018

The output hash ^^ is exactly what nix-prefetch-url --unpack returned.

@andrewchambers

This comment has been minimized.

andrewchambers commented Feb 21, 2018

nix-prefetch-git

@bhipple

This comment has been minimized.

Contributor

bhipple commented Mar 4, 2018

For emacs users, it's worth noting that there's a packages that will let you update fetchgit, fetchurl, etc. shas directly within your editor:
https://github.com/jwiegley/nix-update-el

@shlevy shlevy added the backlog label Apr 1, 2018

@shlevy shlevy self-assigned this Apr 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment