Théo Zimmermann edited this page Dec 23, 2018 · 1 revision

The Nix package manager can be used on any Linux distribution or on macOS or on Windows (thanks to Windows Subsystem for Linux). It is a source-based package manager with a binary cache.

The nixpkgs collection includes packages for the latest releases but also some older releases (going back to Coq 8.5 at the time of writing): when installing any of these Coq versions, the package binary will be fetched from Nix's official binary cache. The collection also includes Coq libraries and plugins but these are not pre-built.

Development package

In addition, Coq's sources include a default.nix file which allow using Nix to install Coq's development version. This can be useful in particular to setup CI (read more about this on the coq-community wiki).

Coq's development Nix package is built on CI and uploaded to the binary cache. If you tell Nix to use this binary cache, then you will be able to install Coq's development version without having to recompile it (which is an advantage over using opam for instance).

For instance, this two-line script will install Coq without rebuilding it:

path=$(nix-prefetch-url --unpack '' --name source 2>&1 | tee /dev/stderr | grep -m1 '^path is' | cut -d\' -f2)
nix-env -if "$path" --extra-substituters "" --trusted-public-keys ""

You may run the command with --dry-run first to make sure that it is going to fetch rather than to build the package. If it is not the case, it might be because your user has not the permissions to trust and extra binary cache, or because the CI build has not finished (go to and try to check if the "pkg:nix" job of the latest pipeline on master has passed —unfortunately there is no direct permalink to check this).

You may want to test Coq without installing it. In this case, you can run the following command:

nix-shell -p "import (fetchTarball {}" --extra-substituters "" --trusted-public-keys ""

Understanding the two line script above

Basically the problem is that you can only benefit from the cached build if you try to build the exact same derivation as was built on CI. You can check this by running nix-env -if "" --dry-run. At the time of writing it says:

these derivations will be built:

Even though the derivation that was built on CI was /nix/store/nxm9falxf7v4bbikyvg87jhlhzii2vg5-coq.

As you can see the hashes are not the same. This is quite annoying but the difference comes from where it gets its source. The Coq derivation will depend on the source derivation (including the name of this derivation), and this name component is very unstable because it depends where the source is located and how it is fetched.

To see better what is happening let's decompose the above nix-env command into the fetching of the tarball and the building of the derivation:

$ nix-prefetch-url --unpack ""
path is '/nix/store/dc0dccxy1v3p72k1f1hk0ky6h1522bkm-master'

$ nix-env -if /nix/store/dc0dccxy1v3p72k1f1hk0ky6h1522bkm-master --dry-run --extra-substituters "" --trusted-public-keys ""
these derivations will be built:

As you can see the hash is the same as before. But you can also notice that the name of the source derivation is "master" whereas on CI it is "source" (which is a more stable name). Now let's run it with an additional argument to change the name of the source derivation:

$ nix-prefetch-url --unpack "" --name source
path is '/nix/store/6zy1q2z9rm7n9p6g88yncgqp8g445lji-source'

$ nix-env -if /nix/store/6zy1q2z9rm7n9p6g88yncgqp8g445lji-source/ --dry-run --extra-substituters "" --trusted-public-keys ""
these paths will be fetched (116.54 MiB download, 622.85 MiB unpacked):

Notice that now the Coq derivation has the same hash as on CI and Nix says "these paths will be fetched" instead of "these derivations will be built".

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.