Skip to content

Commit 4f429fd

Browse files
committed
Implement Nix CI workflow on GitHub instead of CircleCI
Signed-off-by: Benoit Donneaux <benoit@leastauthority.com>
1 parent 2bc29b5 commit 4f429fd

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

.github/workflows/nix.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: Nix
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- '.github/workflows/nix.yml'
9+
- 'flake.*'
10+
- 'setup.cfg'
11+
- '*.nix'
12+
- '*.py'
13+
- '*.ini'
14+
pull_request:
15+
paths:
16+
- '.github/workflows/nix.yml'
17+
- 'flake.*'
18+
- 'setup.cfg'
19+
- '*.nix'
20+
- '*.py'
21+
- '*.ini'
22+
23+
jobs:
24+
check:
25+
runs-on: ubuntu-22.04
26+
outputs:
27+
NIXPKGS: ${{ steps.prep.outputs.NIXPKGS }}
28+
NIX_PATH: ${{ steps.prep.outputs.NIX_PATH }}
29+
env:
30+
nixpkgs: nixos-24_05
31+
steps:
32+
- name: Checkout
33+
id: checkout
34+
uses: actions/checkout@v4
35+
36+
- name: Install nix
37+
id: install_nix
38+
uses: nixbuild/nix-quick-install-action@v28
39+
40+
- name: Show the flake
41+
id: show
42+
run: |
43+
nix flake show
44+
45+
- name: Check the flake
46+
id: check
47+
env:
48+
# FIXME: Our python39 package depends on some broken zope
49+
NIXPKGS_ALLOW_BROKEN: 1
50+
run: |
51+
nix flake check --impure
52+
53+
- name: Restore and cache Nix store for nixpkgs-${{ env.nixpkgs }}
54+
uses: nix-community/cache-nix-action@v5
55+
with:
56+
# restore and save a cache using this key
57+
primary-key: nixpkgs-${{ env.nixpkgs }}-${{ hashFiles('flake.*', '*.nix') }}
58+
# if there's no cache hit, restore a cache by this prefix
59+
restore-prefixes-first-match: nixpkgs-${{ env.nixpkgs }}-
60+
# collect garbage until Nix store size (in bytes) is at most this number
61+
# before trying to save a new cache
62+
gc-max-store-size-linux: 1073741824
63+
# do purge caches
64+
purge: true
65+
# purge all versions of the cache
66+
purge-prefixes: nixpkgs-${{ env.nixpkgs }}-
67+
# created more than 0 seconds ago relative to the start of the `Post Restore` phase
68+
purge-created: 0
69+
# except the version with the `primary-key`, if it exists
70+
purge-primary-key: never
71+
72+
- name: Prepare environment
73+
id: prep
74+
run: |
75+
# Get the reference to the nixpkgs pinned in the flake - dirty way
76+
NIXPKGS=$(nix flake metadata | grep -E '[^\w]+nixpkgs-${{ matrix.nixpkgs }}[^\w]+:' | cut -d' ' -f2 | cut -d'?' -f1)
77+
NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/${NIXPKGS##*/}.tar.gz
78+
# Pass those variables to the next steps and jobs
79+
echo NIXPKGS=$NIXPKGS | tee -a $GITHUB_ENV >> $GITHUB_OUTPUT
80+
echo NIX_PATH=$NIX_PATH | tee -a $GITHUB_ENV >> $GITHUB_OUTPUT
81+
82+
- name: Generate version
83+
# The Nix package doesn't know how to do this part, unfortunately.
84+
run: |
85+
nix-shell \
86+
-p 'python3.withPackages (ps: [ ps.setuptools ])' \
87+
--run 'python setup.py update_version'
88+
89+
packaging:
90+
runs-on: ubuntu-22.04
91+
needs: check
92+
env:
93+
NIXPKGS: ${{ needs.check.outputs.NIXPKGS }}
94+
NIX_PATH: ${{ needs.check.outputs.NIX_PATH }}
95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
python-version:
99+
- 310
100+
- 311
101+
nixpkgs:
102+
- nixos-24_05
103+
steps:
104+
- name: Checkout
105+
id: checkout
106+
uses: actions/checkout@v4
107+
108+
- name: Install nix
109+
id: install_nix
110+
uses: nixbuild/nix-quick-install-action@v28
111+
112+
- name: Restore and cache Nix store for nixpkgs-${{ matrix.nixpkgs }}
113+
uses: nix-community/cache-nix-action@v5
114+
with:
115+
# restore and save a cache using this key
116+
primary-key: python${{ matrix.python-version }}-nixpkgs-${{ matrix.nixpkgs }}-${{ hashFiles('flake.*', '*.nix') }}
117+
# if there's no cache hit, restore a cache by this prefix
118+
restore-prefixes-first-match: nixpkgs-${{ matrix.nixpkgs }}-
119+
# collect garbage until Nix store size (in bytes) is at most this number
120+
# before trying to save a new cache
121+
gc-max-store-size-linux: 1073741824
122+
# do purge caches
123+
purge: true
124+
# purge all versions of the cache
125+
purge-prefixes: python${{ matrix.python-version }}-nixpkgs-${{ matrix.nixpkgs }}-
126+
# created more than 0 seconds ago relative to the start of the `Post Restore` phase
127+
purge-created: 0
128+
# except the version with the `primary-key`, if it exists
129+
purge-primary-key: never
130+
131+
- name: Build package
132+
env:
133+
# CircleCI build environment looks like it has a zillion and a half cores.
134+
# Don't let Nix autodetect this high core count because it blows up memory
135+
# usage and fails the test run. Pick a number of cores that suits the build
136+
# environment we're paying for (the free one!).
137+
DEPENDENCY_CORES: 3
138+
run: |
139+
nix build \
140+
--verbose \
141+
--print-build-logs \
142+
--cores "$DEPENDENCY_CORES" \
143+
--override-input nixpkgs "$NIXPKGS" \
144+
.#python${{ matrix.python-version }}-tahoe-lafs
145+
146+
- name: Unit test
147+
env:
148+
# Once dependencies are built, we can allow some more concurrency for our own
149+
# test suite.
150+
UNITTEST_CORES: 8
151+
run: |
152+
nix run \
153+
--override-input nixpkgs "$NIXPKGS" \
154+
.#python${{ matrix.python-version }}-unittest -- \
155+
--jobs $UNITTEST_CORES \
156+
allmydata

0 commit comments

Comments
 (0)