Skip to content

Commit f0b5ba8

Browse files
committed
perf(ci): pin crane deps in a Nix profile to persist across runs
The check, test, and native-build jobs recompiled the entire crate dependency set (~3 min on the arm runner) on nearly every run, even though the deps derivation is deterministic. The Blacksmith sticky disk persists the store but trims it to GC roots on commit, and crane's cargoArtifacts is an unrooted intermediate (referenced only at build time), so it was dropped and rebuilt. Pin the deps into a Nix profile after they are built. Profiles are the one root that survives the trim (confirmed by inspecting a restored disk and a CI A/B: `nix flake check` dropped from ~184s to ~38s with zero dependency recompilation on the warm run). - new `pin-nix-deps` composite action: `nix-env --set` the cargoArtifacts path into /nix/var/nix/profiles/ccusage-deps. - check + test jobs pin the glibc deps (`.#ccusage.cargoArtifacts`). - the Linux native build pins the musl deps (`.#ccusage-static.cargoArtifacts`); re-expose them via passthru. Each job has its own sticky disk, so each pins its own deps.
1 parent f28fa45 commit f0b5ba8

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎.github/actions/build-linux-native-package/action.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ runs:
2626
nix build .#ccusage-static --print-build-logs
2727
fi
2828
29+
- uses: ./.github/actions/pin-nix-deps
30+
with:
31+
attr: .#ccusage-static.cargoArtifacts
32+
2933
- name: Verify Linux binary is static
3034
shell: bash
3135
env:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Pin Nix deps cache
2+
description: >
3+
Pin a crane cargoArtifacts derivation into a Nix profile so it survives the
4+
Blacksmith sticky disk's GC-root-respecting trim. The deps are an unrooted
5+
intermediate, so without a profile root they are dropped on commit and
6+
recompiled (~3min) on every run; a profile is the one root that persists.
7+
inputs:
8+
attr:
9+
description: Flake attribute of the cargoArtifacts derivation to pin
10+
required: true
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Pin Rust deps in a Nix profile
15+
shell: bash
16+
env:
17+
DEPS_ATTR: ${{ inputs.attr }}
18+
run: |
19+
# The deps were already realized by the preceding build/check, so this
20+
# only ensures the path and roots it; it does not recompile.
21+
nix build "$DEPS_ATTR" --no-link --print-build-logs
22+
nix-env --profile /nix/var/nix/profiles/ccusage-deps --set "$(nix eval --raw "$DEPS_ATTR.outPath")"

‎.github/workflows/ci.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
3131
- uses: ./.github/actions/setup-nix
3232
- run: nix flake check --print-build-logs
33+
- uses: ./.github/actions/pin-nix-deps
34+
with:
35+
attr: .#ccusage.cargoArtifacts
3336
- run: nix develop --command just typecheck
3437

3538
test:
@@ -62,6 +65,9 @@ jobs:
6265
run: just test-vitest
6366
- name: Run Rust tests
6467
run: nix build .#ccusage-tests --print-build-logs
68+
- uses: ./.github/actions/pin-nix-deps
69+
with:
70+
attr: .#ccusage.cargoArtifacts
6571

6672
build-native-packages:
6773
needs: changes

‎nix/static-package.nix‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ in
7272
staticCommonArgs
7373
// {
7474
cargoArtifacts = staticCargoArtifacts;
75+
# Exposed so CI can pin the deps-only artifacts with a Nix profile
76+
# root and keep them on the sticky disk across runs; otherwise the
77+
# store path is unreferenced once the binary is built and the disk's
78+
# GC-root-respecting trim drops it, forcing a full dependency rebuild.
79+
passthru = {
80+
cargoArtifacts = staticCargoArtifacts;
81+
};
7582
# A PT_INTERP header means the binary requests a dynamic loader,
7683
# so it would not run on end-user machines without the build-time
7784
# loader path. READELF is exported by the cross bintools wrapper.

0 commit comments

Comments
 (0)