Generate a file hash similar to the one output by nix-prefetch-url

Suppose i’ve got a zip file available under some URL. I need to get its hash, which should be identical to the one output by nix-prefetch-url --unpack <URL> , but without a working Nix installation. How can one do it?

I tried to understand the C++ implementation of nix-prefetch-url in nix/ at 027f6a735fa72b65825eb9fa870affed045c8f1d · NixOS/nix · GitHub, but it’s a bit complicated.

I’m pretty sure that it just adds it to the nix store, which won’t work without a nix setup: nix/ at 027f6a735fa72b65825eb9fa870affed045c8f1d · NixOS/nix · GitHub

The nix manual has a good explanation in nix-hash though: nix-hash

The nix pills cover the topic, too: NixOS - Nix Pills

It’s a little more complex because it needs to deal with directory trees as well as just raw files.

If you don’t want to use nix-hash either, the implementation of the nix-hash hashing stuff is in nix/ at 0b2ea0023c81e8631df549dce996833ab5213a4a · NixOS/nix · GitHub. it just uses a sha256sum to my knowledge though, at least once you’ve figured out how to structure a NAR.

Thanks a lot @TLATER for a detailed response! It explains a lot. Provided links are very helpful.
So no easy way to simulate it - i’ll find a workaround then.


You may try with to do fetching & hashing without a proper nix store.

1 Like
Hosted by Flying Circus.