how does nix know what binary a machine needs?

268 views Asked by At

They write it in the nix documentation:

However, Nix can automatically skip building from source and instead use a binary cache, a web server that provides pre-built binaries. For instance, when asked to build /nix/store/b6gvzjyb2pg0…-firefox-33.1 from source, Nix would first check if the file https://cache.nixos.org/b6gvzjyb2pg0….narinfo exists, and if so, fetch the pre-built binary referenced from there; otherwise, it would fall back to building from source.

I wonder how does nix know what kind of binary my machine needs? Say if I ran nix on arm or intel or amd or you name it. How are the binaries from this cache selected for the right architecture?

1

There are 1 answers

0
Daniel Jour On BEST ANSWER

nix is a purely functional package manager. As such it takes everything a package needs as input for a function, including the so called stdEnv, which contains information about the architecture.

Using these inputs nix generates a hash. This is what you see in front of the package name.

So the architecture needed is encoded in that hash, which is why when downloading from a binary cache only the hash needs to be checked.