CI: speed up nix-shell cargo test/clippy (persist target cache + pin flake + sccache opt-in) #2

Open
opened 2026-08-19 06:38:50 +00:00 by gal-bot · 2 comments
Owner

The CI cargo test --lib + cargo clippy steps take ~8 min via nix shell github:NixOS/nixpkgs/nixos-25.11#rustc #cargo #clippy #gcc. This is the single biggest iteration friction (local incremental builds are ~18s).

Three levers:

  1. Pin the flake locally. The flake ref github:NixOS/nixpkgs/nixos-25.11 fetches nixpkgs from github on every run (network + eval). Pin to the runner's local channel or commit-checkout a flake.lock so nixpkgs is already in the store.
  2. Persist the cargo target/ dir across runs. Verify whether the act workspace target/ survives between runs; if not, set CARGO_TARGET_DIR under the persistent runner cache (e.g. /var/lib/forgejo-runner/.cache/<slug>-target) so incremental builds reuse compiled deps.
  3. Opt-in sccache via RUSTC_WRAPPER=sccache + SCCACHE_DIR (depends on sccache installed on the runner — platform prerequisite, separate ticket). Caches compilation artifacts across runs.

Observed: run 60's CI compiled tokio from scratch despite deps being unchanged from the prior run — target cache is not being reused.

The CI `cargo test --lib` + `cargo clippy` steps take ~8 min via `nix shell github:NixOS/nixpkgs/nixos-25.11#rustc #cargo #clippy #gcc`. This is the single biggest iteration friction (local incremental builds are ~18s). Three levers: 1. **Pin the flake locally.** The flake ref `github:NixOS/nixpkgs/nixos-25.11` fetches nixpkgs from github on every run (network + eval). Pin to the runner's local channel or commit-checkout a flake.lock so nixpkgs is already in the store. 2. **Persist the cargo target/ dir across runs.** Verify whether the act workspace target/ survives between runs; if not, set `CARGO_TARGET_DIR` under the persistent runner cache (e.g. `/var/lib/forgejo-runner/.cache/<slug>-target`) so incremental builds reuse compiled deps. 3. **Opt-in sccache** via `RUSTC_WRAPPER=sccache` + `SCCACHE_DIR` (depends on sccache installed on the runner — platform prerequisite, separate ticket). Caches compilation artifacts across runs. Observed: run 60's CI compiled tokio from scratch despite deps being unchanged from the prior run — target cache is not being reused.
Owner

Superseded by #11 (migrate to dynamic-nix). dynamic-nix has no Containerfile, so cargo-chef (#3) and sccache (#2) become throwaway work — nix build derivation caching replaces both. Do not start these until #11 is decided. If #11 does not proceed, these remain valid.

Superseded by #11 (migrate to dynamic-nix). dynamic-nix has no Containerfile, so cargo-chef (#3) and sccache (#2) become throwaway work — nix build derivation caching replaces both. Do not start these until #11 is decided. If #11 does not proceed, these remain valid.
Owner

Superseded by #11 (migrate to dynamic-nix). dynamic-nix has no Containerfile, so cargo-chef (#3) and sccache (#2) become throwaway work — nix build derivation caching replaces both. Do not start these until #11 is decided. If #11 does not proceed, these remain valid.

Superseded by #11 (migrate to dynamic-nix). dynamic-nix has no Containerfile, so cargo-chef (#3) and sccache (#2) become throwaway work — nix build derivation caching replaces both. Do not start these until #11 is decided. If #11 does not proceed, these remain valid.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gal/constructionbot#2
No description provided.