52 lines
1.6 KiB
Markdown
52 lines
1.6 KiB
Markdown
|
---
|
||
|
id: nixos-ci
|
||
|
aliases: []
|
||
|
tags: []
|
||
|
---
|
||
|
|
||
|
# Continuous integration in Nix projects
|
||
|
|
||
|
This is where I'm keeping all of my research and notes on continuous
|
||
|
integration in the Nix ecosystem.
|
||
|
|
||
|
One of the very powerful parts of using Nix to manage your project builds and
|
||
|
dependencies is being able to have one single source of truth, for development,
|
||
|
deployment, and CI. You write your Nix expressions once and get the same
|
||
|
environment everywhere. No need to specify dependencies again and again for
|
||
|
every single environment. Mitchell Hashimoto has written about this extensively
|
||
|
[on his
|
||
|
blog](https://mitchellh.com/writing/nix-with-dockerfiles).
|
||
|
|
||
|
## Basic GitHub action
|
||
|
|
||
|
A guilty habit I've gotten into is setting up CI for every single project I
|
||
|
work on and really putting those GitHub actions free minutes to use. It's so
|
||
|
trivial when using Nix, since you literally don't have to do anything extra the
|
||
|
majority of the time. Just copy paste in a GitHub action that installs Nix and
|
||
|
runs `nix build`. That's it.
|
||
|
|
||
|
```yaml
|
||
|
name: "Check and build flake"
|
||
|
on:
|
||
|
pull_request:
|
||
|
push:
|
||
|
branches: [main]
|
||
|
|
||
|
jobs:
|
||
|
lints:
|
||
|
name: Build
|
||
|
runs-on: ubuntu-latest
|
||
|
steps:
|
||
|
- uses: actions/checkout@v4
|
||
|
- name: Check flake inputs
|
||
|
uses: DeterminateSystems/flake-checker-action@v4
|
||
|
- name: Install Nix
|
||
|
uses: DeterminateSystems/nix-installer-action@main
|
||
|
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||
|
- run: nix flake check --all-systems
|
||
|
- run: nix build .
|
||
|
```
|
||
|
|
||
|
This action can basically be dropped in as-is to a Nix project and start
|
||
|
providing basic CI.
|