Nix on Travis: Difference between revisions

From NixOS Wiki
imported>Vbgl
Creation
 
imported>Vbgl
on caching
Line 2: Line 2:


See [https://docs.travis-ci.com/user/languages/nix Travis-CI documentation for Nix].
See [https://docs.travis-ci.com/user/languages/nix Travis-CI documentation for Nix].
== Caching dependencies ==
Build dependencies are usually downloaded from some online public binary cache; but some dependencies are not available on such a cache and must be built on the CI machine on every run. It is however possible to reuse the result of such local builds from one run of the CI script to the next one by means of [https://docs.travis-ci.com/user/caching/ Travis CI caching feature].
A Nix binary cache can be set up in a local directory (say ''~/nix.store'') which will be preserved between CI runs:
<pre>cache:
  directories:
  - $HOME/nix.store</pre>
Nix must then be configured to read from this local binary cache:
<pre>before_install:
- sudo mkdir -p /etc/nix
- echo "binary-caches = https://cache.nixos.org/ file://$HOME/nix.store" | sudo tee -a /etc/nix/nix.conf > /dev/null
- echo 'require-sigs = false' | sudo tee -a /etc/nix/nix.conf > /dev/null</pre>
The first line ensures the directory holding Nix’s configuration files exists.
The second line declares two binary cache: the main only hydra cache and the locally cached directory.
The third line declares that cached closures need not be signed; indeed the local directory will not be signed.
Finally, actual data must be stored in the cache:
<pre>before_cache:
- mkdir -p $HOME/nix.store
- nix copy --to file://$HOME/nix.store -f default.nix buildInputs</pre>
In this example, the ''buildInputs'' from ''default.nix'' are added to the binary cache.
NB: in this setting, the cache only grows. It might be manually deleted when it becomes too bloated but smarter eviction strategies can be implemented too!

Revision as of 06:48, 7 May 2018

Travis-CI provides a language: nix setting (to put in a .travis.yml file) to run continuous integration scripts on a machine with Nix installed.

See Travis-CI documentation for Nix.

Caching dependencies

Build dependencies are usually downloaded from some online public binary cache; but some dependencies are not available on such a cache and must be built on the CI machine on every run. It is however possible to reuse the result of such local builds from one run of the CI script to the next one by means of Travis CI caching feature.

A Nix binary cache can be set up in a local directory (say ~/nix.store) which will be preserved between CI runs:

cache:
  directories:
  - $HOME/nix.store

Nix must then be configured to read from this local binary cache:

before_install:
- sudo mkdir -p /etc/nix
- echo "binary-caches = https://cache.nixos.org/ file://$HOME/nix.store" | sudo tee -a /etc/nix/nix.conf > /dev/null
- echo 'require-sigs = false' | sudo tee -a /etc/nix/nix.conf > /dev/null

The first line ensures the directory holding Nix’s configuration files exists. The second line declares two binary cache: the main only hydra cache and the locally cached directory. The third line declares that cached closures need not be signed; indeed the local directory will not be signed.

Finally, actual data must be stored in the cache:

before_cache:
- mkdir -p $HOME/nix.store
- nix copy --to file://$HOME/nix.store -f default.nix buildInputs

In this example, the buildInputs from default.nix are added to the binary cache.

NB: in this setting, the cache only grows. It might be manually deleted when it becomes too bloated but smarter eviction strategies can be implemented too!