Optimizing Nix Flakes & Binary Caches on Self-Hosted GitLab Runners
flake.nix builds. Measuring runner trace phases alongside Nix build logs isolates cache misses from evaluation overhead, while deterministic flake graph pruning skips unaffected Nix jobs completely.
Why self-hosted Nix CI feels painfully slow (and what Garnix's shutdown changed)
After hosted Nix CI services like Garnix shut down in July 2026, robotics, defense, and deep-tech teams running Nix monorepos consolidated back onto self-hosted GitLab Runners. Out of the box, GitLab Docker executors destroy /nix/store at the end of every job, turning a 5-second incremental build into a multi-minute store copy or source compilation on every push.
Step 1: Separate runner prep time from actual Nix compilation
GitLab's default UI shows a single total job duration. In our self-hosted benchmark, build-nix-env reported 103 seconds, but GitLab Runner section timestamps showed 88 seconds was image pull and executor prep and only 15 seconds was step_script.
wake xray parses both GitLab Runner trace sections (prepare_executor, get_sources, restore_cache, step_script) and Nix build output (these N derivations will be built vs. these M paths will be fetched) to compute the real binary-cache hit rate (WAKE-010):
docker run --rm -v "$PWD:/out" -e GITLAB_TOKEN \
ghcr.io/strange-metal/wake:latest \
wake xray --gitlab-url https://git.your-vpc.internal \
--project robotics/monorepo --html /out/nix-xray.html
- Hit rate below 70%: Point runners at a VPC-local binary cache (Attic, Harmonia, or S3-backed Nix store) and push built paths in a post-build hook on
develop. - High
prepare_executortime: Switch runnerpull_policytoif-not-presentand mount a shared read-only Nix store or persistent daemon socket where isolation policy permits.
Step 2: Trace flake.nix and callPackage deterministically
In a polyglot monorepo mixing Nix flakes with Python, Rust, Go, and TypeScript packages, editing a frontend stylesheet should never trigger a nix build .#firmware job. Wake's deterministic graph scanner parses:
- Root and sub-directory
flake.nixfiles, including localpath:flake inputs. callPackage ./packages/...references andself.packagesoutputs indefault.nixandflake.nix.- Cross-ecosystem edges between Nix devShells/packages and
Cargo.toml,pyproject.toml,go.mod, andpackage.json.
Combined with GitLab's native Dynamic Child Pipelines, Nix derivations run only when their own source files, local flake inputs, or root flake.lock actually change, while merges to default branches always execute the full Nix check matrix.
Measure your Nix binary-cache hit rate in 2 minutes
Wake runs 100% inside your VPC with zero source-code egress. See a real offline report in our live X-Ray flamegraph or email us for a 15-minute walkthrough.
Email chris@wakeci.dev