alexandria/content/Hacks/nixos-ci.md

51 lines
1.6 KiB
Markdown
Raw Normal View History

2025-01-01 03:50:02 -08:00
---
id: nixos-ci
aliases: []
tags: []
2025-01-01 03:53:51 -08:00
title: Continuous integration in Nix projects
2025-01-01 03:50:02 -08:00
---
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.