Skip to content

Commit ea30778

Browse files
committed
ci(nix): split development flake setup
Move development-only Nix modules into dev/flake.nix so root package builds no longer carry treefmt, git-hooks, and agent-skills inputs. Switch setup-nix to nix-quick-install-action, split package and development cache scopes, and stop warming the dev shell by default. Add just tasks for frozen pnpm installs and large fixture generation so CI workflows call shared recipes instead of repeating command lines.
1 parent 6cafadf commit ea30778

14 files changed

Lines changed: 513 additions & 247 deletions

File tree

‎.envrc‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ if has nix; then
77
# dev shell — e.g. an outdated treefmt wrapper in the installed git hooks.
88
watch_file flake.nix
99
watch_file flake.lock
10+
watch_file dev/flake.nix
11+
watch_file dev/flake.lock
1012
watch_file rust-toolchain.toml
1113
watch_dir nix
12-
use flake
14+
use flake ./dev
1315
fi
Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
11
name: Setup Nix
22
description: Install Nix and restore the Nix store from the GitHub Actions cache
3+
inputs:
4+
cache-profile:
5+
description: Which Nix cache key scope to use
6+
default: package
7+
warm-dev-shell:
8+
description: Whether to instantiate the CI dev shell during setup
9+
default: 'false'
310
runs:
411
using: composite
512
steps:
613
- name: Install Nix
7-
uses: cachix/install-nix-action@8aa03977d8d733052d78f4e008a241fd1dbf36b3 # v31.10.6
14+
uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34
815
with:
916
github_access_token: ${{ github.token }}
10-
extra_nix_config: |
17+
nix_conf: |
1118
access-tokens = github.com=${{ github.token }}
1219
13-
- name: Cache Nix store
20+
- name: Cache Nix store for package builds
21+
if: inputs.cache-profile == 'package'
1422
uses: nix-community/cache-nix-action@7df957e333c1e5da7721f60227dbba6d06080569 # v7.0.2
1523
with:
16-
# Hash every input that changes the dev-shell closure, not just
17-
# flake.lock. The previous key only hashed flake.lock, so any
18-
# Cargo.lock / toolchain change rebuilt `ccusage-deps` (~80s) on every
19-
# run while the stale cache stayed frozen and was never re-saved.
20-
#
21-
# `package.json` is the root manifest only: its `version` is read by
22-
# package.nix and baked into the crane derivation name
23-
# (`ccusage-deps-<version>`), so a version bump must rotate the key.
24-
#
25-
# pnpm-lock.yaml and the workspace package.json files are intentionally
26-
# NOT hashed: no Nix derivation consumes JS dependencies. `pnpm install`
27-
# runs in the dev-shell shellHook and writes node_modules in the working
28-
# tree, outside the Nix store, so JS deps never change this cache.
24+
# Package jobs should not rotate when only development tooling changes.
2925
primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('flake.lock', 'flake.nix', 'default.nix', 'package.nix', 'package.json', 'nix/**/*.nix', 'rust-toolchain.toml', 'rust/Cargo.lock', 'rust/**/Cargo.toml') }}
30-
# On a key miss, warm-start from the newest cache for this os/arch so
31-
# only the changed derivations rebuild before the fresh key is saved.
3226
restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }}-
33-
# Bound a single cache so the repo stays under the 10 GB limit. This
34-
# action only runs on Linux (arm64 + x64), so at most two Nix caches
35-
# exist. 3.5 GB each leaves headroom for the small per-platform Cargo
36-
# caches (~1 GB total) used by the macOS/Windows build jobs. The
37-
# dev-shell closure (~2.5 GB) is a gc root, so it survives this trim.
3827
gc-max-store-size-linux: 3500000000
39-
# Purge superseded caches for this os/arch on every run. Without this
40-
# the more frequently rotating key would accumulate stale caches and
41-
# push the repo past the 10 GB limit, evicting the fresh cache via LRU.
42-
# 2 days (not 7) so that several key rotations in one week (e.g.
43-
# repeated Cargo.lock bumps) cannot pile up multiple ~2.5 GB caches.
44-
# The active cache is always the current primary-key, which
45-
# purge-primary-key keeps regardless of age.
4628
purge: true
4729
purge-prefixes: nix-${{ runner.os }}-${{ runner.arch }}-
4830
purge-created: 172800
4931
purge-primary-key: never
5032

51-
- name: Load Nix development environment
33+
- name: Cache Nix store for development jobs
34+
if: inputs.cache-profile == 'dev'
35+
uses: nix-community/cache-nix-action@7df957e333c1e5da7721f60227dbba6d06080569 # v7.0.2
36+
with:
37+
# Development jobs include the separate dev flake and its tooling lock.
38+
primary-key: nix-dev-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('flake.lock', 'flake.nix', 'dev/flake.lock', 'dev/flake.nix', 'default.nix', 'package.nix', 'package.json', 'nix/**/*.nix', 'rust-toolchain.toml', 'rust/Cargo.lock', 'rust/**/Cargo.toml') }}
39+
restore-prefixes-first-match: nix-dev-${{ runner.os }}-${{ runner.arch }}-
40+
gc-max-store-size-linux: 3500000000
41+
purge: true
42+
purge-prefixes: nix-dev-${{ runner.os }}-${{ runner.arch }}-
43+
purge-created: 172800
44+
purge-primary-key: never
45+
46+
- name: Load Nix CI development environment
47+
if: inputs.warm-dev-shell == 'true'
5248
shell: bash
53-
run: nix develop --command true
49+
run: nix develop ./dev#ci --command true

‎.github/workflows/ci.yaml‎

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ jobs:
2828
steps:
2929
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
3030
- uses: ./.github/actions/setup-nix
31+
with:
32+
cache-profile: dev
3133
- run: nix flake check --print-build-logs
32-
- run: nix develop --command just typecheck
34+
- run: nix flake check ./dev --print-build-logs
35+
- run: nix develop ./dev#ci --command just install
36+
- run: nix develop ./dev#ci --command just typecheck
3337

3438
test:
3539
needs: changes
@@ -47,21 +51,24 @@ jobs:
4751
ref: ${{ github.event.pull_request.head.sha || github.sha }}
4852
persist-credentials: false
4953
- uses: ./.github/actions/setup-nix
54+
with:
55+
cache-profile: dev
56+
- run: nix develop ./dev#ci --command just install
5057
- name: Create default Claude directories for tests
5158
run: |
5259
mkdir -p "$HOME/.claude/projects"
5360
mkdir -p "$HOME/.config/claude/projects"
5461
- name: Run test suite
5562
if: github.event_name != 'pull_request' && github.ref != format('refs/heads/{0}', github.event.repository.default_branch)
56-
run: nix develop --command just test
63+
run: nix develop ./dev#ci --command just test
5764
- name: Run Vitest tests
5865
if: github.event_name == 'pull_request' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
59-
run: nix develop --command just test-vitest
66+
run: nix develop ./dev#ci --command just test-vitest
6067
- name: Generate Rust coverage report
6168
if: github.event_name == 'pull_request' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
6269
run: |
6370
mkdir -p coverage
64-
env -u CFLAGS -u CXXFLAGS nix develop --command cargo llvm-cov \
71+
env -u CFLAGS -u CXXFLAGS nix develop ./dev#ci --command cargo llvm-cov \
6572
--manifest-path rust/Cargo.toml \
6673
--workspace \
6774
--cobertura \
@@ -185,8 +192,9 @@ jobs:
185192
for archive in "$RUNNER_TEMP"/native-packages/*.tar; do
186193
tar -xf "$archive"
187194
done
195+
- run: nix develop ./dev#ci --command just install
188196
- id: publish
189-
run: nix develop --command pnpm pkg-pr-new publish --pnpm --bin './apps/ccusage' './packages/ccusage-*'
197+
run: nix develop ./dev#ci --command pnpm pkg-pr-new publish --pnpm --bin './apps/ccusage' './packages/ccusage-*'
190198

191199
ccusage-preview-e2e:
192200
if: github.event_name == 'pull_request' && needs.changes.outputs.code-changed == 'true'
@@ -252,6 +260,8 @@ jobs:
252260

253261
- name: Setup Nix
254262
uses: ./.github/actions/setup-nix
263+
with:
264+
cache-profile: dev
255265

256266
- name: Resolve PR preview package URL
257267
env:
@@ -264,14 +274,15 @@ jobs:
264274
265275
- name: Generate large ccusage fixture
266276
run: |
267-
nix develop --command pnpm exec bun apps/ccusage/scripts/generate-large-fixture.ts \
268-
--output-dir "$RUNNER_TEMP/ccusage-large-fixture" \
269-
--codex-output-dir "$RUNNER_TEMP/ccusage-large-codex-fixture" \
270-
--size-mib 1024
277+
nix develop ./dev#ci --command just install
278+
nix develop ./dev#ci --command just generate-large-fixture \
279+
"$RUNNER_TEMP/ccusage-large-fixture" \
280+
"$RUNNER_TEMP/ccusage-large-codex-fixture" \
281+
1024
271282
272283
- name: Compare fixture performance
273284
run: |
274-
nix develop --command pnpm exec bun apps/ccusage/scripts/compare-pr-performance.ts \
285+
nix develop ./dev#ci --command pnpm exec bun apps/ccusage/scripts/compare-pr-performance.ts \
275286
--base-package-url "https://pkg.pr.new/${{ github.repository }}/ccusage@${{ github.event.pull_request.base.sha }}" \
276287
--base-sha "${{ github.event.pull_request.base.sha }}" \
277288
--head-dir . \
@@ -298,7 +309,7 @@ jobs:
298309
GITHUB_TOKEN: ${{ github.token }}
299310
GITHUB_REPOSITORY: ${{ github.repository }}
300311
PR_NUMBER: ${{ github.event.pull_request.number }}
301-
run: nix develop --command pnpm exec bun .github/scripts/upsert-pr-comment.ts
312+
run: nix develop ./dev#ci --command pnpm exec bun .github/scripts/upsert-pr-comment.ts
302313

303314
ccusage-rust-perf-comment:
304315
name: ccusage rust perf comment
@@ -322,6 +333,8 @@ jobs:
322333

323334
- name: Setup Nix
324335
uses: ./.github/actions/setup-nix
336+
with:
337+
cache-profile: dev
325338

326339
- name: Resolve PR preview package URL
327340
env:
@@ -334,14 +347,15 @@ jobs:
334347
335348
- name: Generate large ccusage fixture
336349
run: |
337-
nix develop --command pnpm exec bun apps/ccusage/scripts/generate-large-fixture.ts \
338-
--output-dir "$RUNNER_TEMP/ccusage-large-fixture" \
339-
--codex-output-dir "$RUNNER_TEMP/ccusage-large-codex-fixture" \
340-
--size-mib 1024
350+
nix develop ./dev#ci --command just install
351+
nix develop ./dev#ci --command just generate-large-fixture \
352+
"$RUNNER_TEMP/ccusage-large-fixture" \
353+
"$RUNNER_TEMP/ccusage-large-codex-fixture" \
354+
1024
341355
342356
- name: Compare Rust performance
343357
run: |
344-
nix develop --command pnpm exec bun apps/ccusage/scripts/compare-pr-performance.ts \
358+
nix develop ./dev#ci --command pnpm exec bun apps/ccusage/scripts/compare-pr-performance.ts \
345359
--base-package-url "https://pkg.pr.new/${{ github.repository }}/ccusage@${{ github.event.pull_request.base.sha }}" \
346360
--base-sha "${{ github.event.pull_request.base.sha }}" \
347361
--head-dir . \
@@ -369,7 +383,7 @@ jobs:
369383
GITHUB_TOKEN: ${{ github.token }}
370384
GITHUB_REPOSITORY: ${{ github.repository }}
371385
PR_NUMBER: ${{ github.event.pull_request.number }}
372-
run: nix develop --command pnpm exec bun .github/scripts/upsert-pr-comment.ts
386+
run: nix develop ./dev#ci --command pnpm exec bun .github/scripts/upsert-pr-comment.ts
373387

374388
action-timeline:
375389
needs:

‎.github/workflows/release.yaml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343
with:
4444
fetch-depth: 0
4545
- uses: ./.github/actions/setup-nix
46+
with:
47+
cache-profile: dev
4648
if: matrix.platform == 'linux'
4749
- name: Cache Cargo build
4850
if: matrix.platform != 'linux'
@@ -110,7 +112,8 @@ jobs:
110112
for archive in "$RUNNER_TEMP"/native-packages/*.tar; do
111113
tar -xf "$archive"
112114
done
113-
- run: nix develop --command pnpm --filter='./apps/ccusage' --filter='./packages/ccusage-*' publish --provenance --no-git-checks --access public
115+
- run: nix develop ./dev#ci --command just install
116+
- run: nix develop ./dev#ci --command pnpm --filter='./apps/ccusage' --filter='./packages/ccusage-*' publish --provenance --no-git-checks --access public
114117

115118
release:
116119
needs:
@@ -123,6 +126,9 @@ jobs:
123126
with:
124127
fetch-depth: 0
125128
- uses: ./.github/actions/setup-nix
126-
- run: nix develop --command pnpm changelogithub
129+
with:
130+
cache-profile: dev
131+
- run: nix develop ./dev#ci --command just install
132+
- run: nix develop ./dev#ci --command pnpm changelogithub
127133
env:
128134
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

‎.github/workflows/update-pricing.yaml‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
with:
1919
persist-credentials: false
2020
- uses: ./.github/actions/setup-nix
21+
with:
22+
cache-profile: dev
2123
- name: Capture current LiteLLM pricing JSON
2224
run: |
2325
rev="$(jq -r '.nodes.litellm.locked.rev' flake.lock)"
@@ -44,7 +46,8 @@ jobs:
4446
echo "Pricing snapshot is already up to date."
4547
exit 0
4648
fi
47-
nix develop --command just check
49+
nix develop ./dev#ci --command just install
50+
nix develop ./dev#ci --command just check
4851
- name: Create pull request
4952
env:
5053
GH_TOKEN: ${{ github.token }}
@@ -88,12 +91,14 @@ jobs:
8891
with:
8992
persist-credentials: false
9093
- uses: ./.github/actions/setup-nix
94+
with:
95+
cache-profile: dev
9196
- name: Update models.dev input
9297
run: |
9398
nix flake update models-dev
9499
- name: Regenerate committed models.dev pricing snapshot
95100
run: |
96-
nix develop --command just gen-models-dev-pricing
101+
nix develop ./dev#ci --command just gen-models-dev-pricing
97102
- name: Skip lock-only models.dev updates
98103
run: |
99104
# Only the compacted snapshot affects the build; if a models.dev bump
@@ -108,7 +113,8 @@ jobs:
108113
echo "Pricing snapshot is already up to date."
109114
exit 0
110115
fi
111-
nix develop --command just check
116+
nix develop ./dev#ci --command just install
117+
nix develop ./dev#ci --command just check
112118
- name: Create pull request
113119
env:
114120
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)