Continuous Integration (CI): Difference between revisions
Phanirithvij (talk | contribs) add two links to Self-hosted runners |
Link to Nixcademy GitHub Actions tutorial |
||
| (One intermediate revision by one other user not shown) | |||
| Line 7: | Line 7: | ||
<code>nix-build</code> will always ensure the built store path is put in the local store, be it by building or by downloading from a substituter. On CI, we often only want to check whether we can build the derivation, without using or running the output. | <code>nix-build</code> will always ensure the built store path is put in the local store, be it by building or by downloading from a substituter. On CI, we often only want to check whether we can build the derivation, without using or running the output. | ||
This can be achieved by using | This can be achieved by using <code>--dry-run</code> to check whether the result would be fetched, and only building it it has to be built. | ||
[https://gist.github.com/Profpatsch/fbbc9a0006e246076f11efca0387d293 nix-build-if-changed.py] implements this in a relatively straightforward (but naïve) Python script. | [https://gist.github.com/Profpatsch/fbbc9a0006e246076f11efca0387d293 nix-build-if-changed.py] implements this in a relatively straightforward (but naïve) Python script. | ||
[https://github.com/Mic92/nix-build-uncached/ nix-build-uncached] implements it in a slightly more elaborate manner, and is available on nixpkgs (as the <code>nix-build-uncached</code> package). | [https://github.com/Mic92/nix-build-uncached/ nix-build-uncached] implements it in a slightly more elaborate manner, and is available on nixpkgs (as the <code>nix-build-uncached</code> package). | ||
== Caching built results == | |||
After building your project you might want to cache the results. The cache server could be a [https://cachix.org/ Cachix] cache, a self-hosted [https://github.com/zhaofengli/attic Attic] cache or even your own nix machine. | |||
[https://github.com/Mic92/nix-fast-build nix-fast-build] uses <code>nix-eval-jobs</code> in parallel to speed-up the evaluation and building process. It's useful for building flakes that have multiple outputs. It also supports uploading to [https://cachix.org/ Cachix] and [https://github.com/zhaofengli/attic Attic]. | |||
You can also use <code>nix-copy-closure</code> to directly upload to a remote /nix/store through a SSH connection. As it's already built in Nix, It's the simplest way to cache the results. Albeit, in my experience it's slower.[citation needed] | |||
== Instructions for specific CI Providers == | == Instructions for specific CI Providers == | ||
| Line 23: | Line 31: | ||
See [https://github.com/cachix/install-nix-action install-nix-action] to install nix in Linux/macOS actions. | See [https://github.com/cachix/install-nix-action install-nix-action] to install nix in Linux/macOS actions. | ||
There is also [https://github.com/cachix/cachix-action one action] to setup [https://cachix.org/ cachix], a hosted binary cache. | There is also [https://github.com/cachix/cachix-action one action] to setup [https://cachix.org/ cachix], a hosted binary cache. | ||
[https://nixcademy.com/posts/nixos-integration-test-on-github/ Test Your Apps and Services with GitHub Actions Quickly and for Free, a Nixcademy tutorial] | |||
==== Self-hosted runners ==== | ==== Self-hosted runners ==== | ||