Continuous Integration (CI): Difference between revisions

imported>Srid
Add https://github.com/juspay/jenkins-nix-ci
Link to Nixcademy GitHub Actions tutorial
 
(6 intermediate revisions by 6 users 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 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 ====
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 ===  
Line 35: Line 49:


=== Jenkins ===
=== Jenkins ===
 
[[Jenkins]]
[https://github.com/juspay/jenkins-nix-ci jenkins-nix-ci]: A NixOS module for Jenkins, optimized specifically for running projects using Nix.
 
[https://github.com/mrVanDalo mrVanDalo] has a [https://git.ingolf-wagner.de/palo/nixos-config/src/branch/main/nixos/library/jenkins.nix library] to declare jenkins in his repository. It can be used as shown [https://git.ingolf-wagner.de/palo/nixos-config/src/branch/main/nixos/configs/workhorse/jenkins.nix here]


=== Gitlab ===
=== Gitlab ===
Line 51: Line 62:


[https://sourcehut.org Sourcehut] provides [https://man.sr.ht/builds.sr.ht/compatibility.md#nixos an official NixOS image]
[https://sourcehut.org Sourcehut] provides [https://man.sr.ht/builds.sr.ht/compatibility.md#nixos an official NixOS image]
[[Category:Server]]
[[Category:Applications]]