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 https://coq.cachix.org 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 'https://github.com/coq/coq/tarball/master' --name source 2>&1 | tee /dev/stderr | grep -m1 '^path is' | cut -d\' -f2)
nix-env -if "$path" --extra-substituters "https://coq.cachix.org" --trusted-public-keys "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= coq.cachix.org-1:Jgt0DwGAUo+wpxCM52k2V+E0hLoOzFPzvg94F65agtI="

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 https://gitlab.com/coq/coq/pipelines 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 https://github.com/coq/coq/tarball/master) {}" --extra-substituters "https://coq.cachix.org" --trusted-public-keys "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= coq.cachix.org-1:Jgt0DwGAUo+wpxCM52k2V+E0hLoOzFPzvg94F65agtI="

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 "https://github.com/coq/coq/tarball/master" --dry-run. At the time of writing it says:

these derivations will be built:
  /nix/store/7n54i9rhwzb6d4mh3wv7c1fmd05dyjh4-coq.drv

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 "https://github.com/coq/coq/tarball/master"
unpacking...
path is '/nix/store/dc0dccxy1v3p72k1f1hk0ky6h1522bkm-master'
09x8g81qhdi29j00c08p091q30rlzafhlard6ghl69dx7218hssl

$ nix-env -if /nix/store/dc0dccxy1v3p72k1f1hk0ky6h1522bkm-master --dry-run --extra-substituters "https://coq.cachix.org" --trusted-public-keys "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= coq.cachix.org-1:Jgt0DwGAUo+wpxCM52k2V+E0hLoOzFPzvg94F65agtI="
these derivations will be built:
  /nix/store/7n54i9rhwzb6d4mh3wv7c1fmd05dyjh4-coq.drv

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 "https://github.com/coq/coq/tarball/master" --name source
unpacking...
path is '/nix/store/6zy1q2z9rm7n9p6g88yncgqp8g445lji-source'
09x8g81qhdi29j00c08p091q30rlzafhlard6ghl69dx7218hssl

$ nix-env -if /nix/store/6zy1q2z9rm7n9p6g88yncgqp8g445lji-source/ --dry-run --extra-substituters "https://coq.cachix.org" --trusted-public-keys "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= coq.cachix.org-1:Jgt0DwGAUo+wpxCM52k2V+E0hLoOzFPzvg94F65agtI="
these paths will be fetched (116.54 MiB download, 622.85 MiB unpacked):
  /nix/store/nxm9falxf7v4bbikyvg87jhlhzii2vg5-coq

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.