Continuous Integration (CI): Difference between revisions

m Drop banned user's contribution
Added a section about caching binary results in CI
 
(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 `--dry-run` to check whether the result would be fetched, and only building it it has to be built.
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 26: Line 34:
==== Self-hosted runners ====
==== Self-hosted runners ====


NixOS has a module for running self-hosted GitHub runners.
NixOS has a few unofficial modules for running self-hosted GitHub runners. see [https://nix-community.github.io/srvos/github_actions_runner srvos], [https://github.com/juspay/github-nix-ci juspay/github-nix-ci]


=== Build kite ===  
=== Build kite ===