Skip to content

Instantly share code, notes, and snippets.

@boxofrox
Created November 16, 2017 17:30
Show Gist options
  • Save boxofrox/d8a3080fbb03f84b7d7a31e102b35f09 to your computer and use it in GitHub Desktop.
Save boxofrox/d8a3080fbb03f84b7d7a31e102b35f09 to your computer and use it in GitHub Desktop.
How to compute the SHA256 hash for a new Nix package?

How does one find the sha256 of a new package?

I read that I should put a garbage sha256 into my package file, build it, and nix will report the correct sha256 I should use.

I put sha256 = "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b" into my package file as the garbage sha256.

When I built the package, the error reports:

output path ‘/nix/store/d7i3y19rsaj8x5x1wmylr7r0y8zl15s0-fuzzy-search’
  has r:sha256 hash ‘03lcjmxw05yrml287ff39wyjpfzph9j5v7h3vq9zk3djlz3k5i4i’
  when ‘0sslrbd0b64gxxcc02afjv7fwkmn4i8w19win08yjvqbr0clgfh1’ was expected

Neither of those hashes are my garbage sha256, so where did the 03lcjmxw05yrml287ff39wyjpfzph9j5v7h3vq9zk3djlz3k5i4i hash come from that was found, and which hash am I supposed to use in my package?

{ stdenv, fetchgit, openssl, pkgconfig, rustPlatform }:
with rustPlatform;
buildRustPackage rec {
name = "fuzzy-search-server-${version}";
version = "0.0.1";
src = fetchgit {
url = "https://git.example.com/dev/fuzzy-search.git";
rev = "refs/tags/v${version}";
sha256 = "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b";
};
depsSha256 = "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b";
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ openssl ];
meta = {
description = "Fuzzy search across mysql tables and fields";
#homepage = https://git.example.com/dev/fuzzy-search.git;
maintainers = [ "boxofrox" ];
inherit version; # testing
};
}
$ nix-build /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs --run-env -A fuzzySearchServer
these derivations will be built:
/nix/store/qvv2mqhy72waxwam2csx2xgfcjmllnjx-rustc-bootstrap-1.19.0.drv
/nix/store/br6kz829w703l6wgbgrfbabwmncd5p2l-rustc-1.20.0.drv
/nix/store/rfacvxr23bmlv12csamh3v8h4y8hp08s-fuzzy-search.drv
/nix/store/syb4kycw3r1jz7vsg1s2f0snhz1v7rjm-cargo-bootstrap-1.19.0.drv
/nix/store/x9xng0hrzdiqmwlrls1ria1ry9yjbjia-cargo-0.22.0-fetch.drv
/nix/store/vf9x3m414agb716irk9jd14shxf2966m-cargo-0.22.0.drv
/nix/store/b8jvmq9mynsykjl1z13gwr7xrbx38gph-fuzzy-search-server-0.0.1-fetch.drv
these paths will be fetched (193.71 MiB download, 244.31 MiB unpacked):
/nix/store/4kn5566mmhzxfz39231kxdwckrxs8hcq-hook
/nix/store/6h3hx7n7945477if07nldjcbn8n0szhh-libuv-1.14.1
/nix/store/c15p7i1wk0pik1w850dcww3ajllh81yr-cargo-0.22.0-src
/nix/store/gwpkffirc7phd1na2g1qwqx4lpwads5k-libffi-3.2.1-dev
/nix/store/ja3da5zk23vnm5nl7m7h068qg03vjcqa-gdb-8.0.1
/nix/store/lar6vr8cc4msa1wws4xiqvwfazrk59x4-rust-1.19.0-x86_64-unknown-linux-gnu.tar.gz
/nix/store/p8r2n494qmajg25wxfzgnkpyscicww12-rustc-1.20.0-src.tar.gz
/nix/store/qpc0w1bpl8jzin7l3vm5pc89f56gsabh-hook
/nix/store/qxa67d95vq23sfgl913v5rmmavy45ffz-hook
/nix/store/rbx6683xf6g5w7b0vdzd773zp1jr35kx-rhash-1.3.3
/nix/store/rd4yi58zk6i7854a26zxih2zrr0abr6q-file-5.32
/nix/store/sn894pcvj7w1bbbmzl9rhbm778wnmj91-libarchive-3.3.2-lib
/nix/store/wvnj828fpihafpmwafsmsxkrzgdr3k9r-cmake-3.8.2
fetching path ‘/nix/store/c15p7i1wk0pik1w850dcww3ajllh81yr-cargo-0.22.0-src’...
fetching path ‘/nix/store/p8r2n494qmajg25wxfzgnkpyscicww12-rustc-1.20.0-src.tar.gz’...
building path(s) ‘/nix/store/d7i3y19rsaj8x5x1wmylr7r0y8zl15s0-fuzzy-search’
fetching path ‘/nix/store/4kn5566mmhzxfz39231kxdwckrxs8hcq-hook’...
exporting https://git.example.com/dev/fuzzy-search.git (rev refs/tags/v0.0.1) into /nix/store/d7i3y19rsaj8x5x1wmylr7r0y8zl15s0-fuzzy-search
*** Downloading ‘https://cache.nixos.org/nar/0nz15i3s1cmag91gz8pb9qv3nk04bd95x75y0zaqjcgia27ysrr8.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/c15p7i1wk0pik1w850dcww3ajllh81yr-cargo-0.22.0-src’...
*** Downloading ‘https://cache.nixos.org/nar/1vj2jf00g41557dzp6kwgwqhdli8k189bi81r40gxyiln8hlz65q.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/p8r2n494qmajg25wxfzgnkpyscicww12-rustc-1.20.0-src.tar.gz’...
Initialized empty Git repository in /nix/store/d7i3y19rsaj8x5x1wmylr7r0y8zl15s0-fuzzy-search/.git/
*** Downloading ‘https://cache.nixos.org/nar/0b0dp6i8cw0ar9mx1fp9kj39q1hjlc1s2srrm63bcwxvi21xm39s.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/4kn5566mmhzxfz39231kxdwckrxs8hcq-hook’...
fetching path ‘/nix/store/rd4yi58zk6i7854a26zxih2zrr0abr6q-file-5.32’...
*** Downloading ‘https://cache.nixos.org/nar/07fi71lmvbdlccdj96fkq7kz5nqpjxqbcm13g2v2gnr87i6v06ig.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/rd4yi58zk6i7854a26zxih2zrr0abr6q-file-5.32’...
fetching path ‘/nix/store/qpc0w1bpl8jzin7l3vm5pc89f56gsabh-hook’...
fetching path ‘/nix/store/qxa67d95vq23sfgl913v5rmmavy45ffz-hook’...
*** Downloading ‘https://cache.nixos.org/nar/1rn0m1r5n18fxw50qj6043mq21c0x1nk4iqlz76j32hih1kp83f8.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/qpc0w1bpl8jzin7l3vm5pc89f56gsabh-hook’...
*** Downloading ‘https://cache.nixos.org/nar/1gpfr74s46qg1k5q03wkc7j1ns2zcy2vi4fynwki6ijaab496cwq.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/qxa67d95vq23sfgl913v5rmmavy45ffz-hook’...
fetching path ‘/nix/store/sn894pcvj7w1bbbmzl9rhbm778wnmj91-libarchive-3.3.2-lib’...
fetching path ‘/nix/store/ja3da5zk23vnm5nl7m7h068qg03vjcqa-gdb-8.0.1’...
*** Downloading ‘https://cache.nixos.org/nar/07w2n6g1dfihy3f5zi8zmvh67pjxyb4znw07sxgm0y1bsbsrkhyf.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/sn894pcvj7w1bbbmzl9rhbm778wnmj91-libarchive-3.3.2-lib’...
*** Downloading ‘https://cache.nixos.org/nar/1skm7gw4pg5p3p6crglch88cap7y6886idz1v1x9apk2hv3y80d8.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/ja3da5zk23vnm5nl7m7h068qg03vjcqa-gdb-8.0.1’...
fetching path ‘/nix/store/gwpkffirc7phd1na2g1qwqx4lpwads5k-libffi-3.2.1-dev’...
*** Downloading ‘https://cache.nixos.org/nar/0lz5g418a7d7mfjhrs0h2zgsmhikrwkjrwqayll8wwryyhrycqhp.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/gwpkffirc7phd1na2g1qwqx4lpwads5k-libffi-3.2.1-dev’...
fetching path ‘/nix/store/6h3hx7n7945477if07nldjcbn8n0szhh-libuv-1.14.1’...
*** Downloading ‘https://cache.nixos.org/nar/0ksc4i643qh5z7pmlk2n8nmmd4lkc8144gxw1pvna1irhmyqrxj5.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/6h3hx7n7945477if07nldjcbn8n0szhh-libuv-1.14.1’...
fetching path ‘/nix/store/rbx6683xf6g5w7b0vdzd773zp1jr35kx-rhash-1.3.3’...
fetching path ‘/nix/store/lar6vr8cc4msa1wws4xiqvwfazrk59x4-rust-1.19.0-x86_64-unknown-linux-gnu.tar.gz’...
*** Downloading ‘https://cache.nixos.org/nar/0wi786x1fbmlzl178xqpawzva1c999blpxgva6imnbl9lh32l62c.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/lar6vr8cc4msa1wws4xiqvwfazrk59x4-rust-1.19.0-x86_64-unknown-linux-gnu.tar.gz’...
*** Downloading ‘https://cache.nixos.org/nar/138bx9zyx0xxrr5x3ri4djkz9abjdc367ql4rbf288mpby4hw960.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/rbx6683xf6g5w7b0vdzd773zp1jr35kx-rhash-1.3.3’...
fetching path ‘/nix/store/wvnj828fpihafpmwafsmsxkrzgdr3k9r-cmake-3.8.2’...
*** Downloading ‘https://cache.nixos.org/nar/1ahxdpb0bifh2a9zzc7l9412d93xzmkgd1awy94lym3nhbd1f3a1.nar.xz’ (signed by ‘cache.nixos.org-1’) to ‘/nix/store/wvnj828fpihafpmwafsmsxkrzgdr3k9r-cmake-3.8.2’...
remote: Counting objects: 39, done.
remote: Compressing objects: 100% (38/38), done.
remote: Total 39 (delta 1), reused 32 (delta 0)
From https://git.example.com/dev/fuzzy-search.git
* tag v0.0.1 -> FETCH_HEAD
Switched to a new branch 'fetchgit'
removing `.git'...
output path ‘/nix/store/d7i3y19rsaj8x5x1wmylr7r0y8zl15s0-phreebooks-search’ has r:sha256 hash ‘03lcjmxw05yrml287ff39wyjpfzph9j5v7h3vq9zk3djlz3k5i4i’ when ‘0sslrbd0b64gxxcc02afjv7fwkmn4i8w19win08yjvqbr0clgfh1’ was expected
killing process 12713
killing process 12702
error: build of ‘/nix/store/rfacvxr23bmlv12csamh3v8h4y8hp08s-phreebooks-search.drv’ failed
/run/current-system/sw/bin/nix-build: failed to build all dependencies
@boxofrox
Copy link
Author

Answered via IRC!

-- Thu, 16 Nov 2017 --
12:31:57         boxofrox | I'm trying to calculate the sha256 for a package I'm making, but I can't figure out how to do it.  I've posted details at https://gist.github.com/boxofrox/d8a3080fbb03f84b7d7a31e102b35f09 , any help is appreciated.
12:33:08           clever | boxofrox: it changed the base for the hash
12:33:36          tilpner | boxofrox - nix-hash --to-base32 --type sha256 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
12:33:58         boxofrox | oh, now that makes sense.
12:34:08                ↪ | thank you
12:34:10           clever | [root@amd-nixos:~]# nix-hash --to-base32 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b --type sha256
12:34:14                ↪ | 0sslrbd0b64gxxcc02afjv7fwkmn4i8w19win08yjvqbr0clgfh1
12:34:18           clever | boxofrox: this returns the 2nd hash in the error message
12:34:59         boxofrox | so I want the first hash then.  sweet
12:35:04           clever | yep

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