How to use the Bazel remote cache and Attic Nix binary cache from CI jobs.
The Bazel remote cache runs as an in-cluster gRPC service:
grpc://bazel-cache.attic-cache-dev.svc.cluster.local:9092
The BAZEL_REMOTE_CACHE environment variable is injected into docker and
nix runner pods automatically.
Add a runner-pool config section to your project’s .bazelrc:
# .bazelrc
build:runner-pool --remote_cache=grpc://bazel-cache.attic-cache-dev.svc.cluster.local:9092
build:runner-pool --remote_upload_local_results=true
build:runner-pool --remote_timeout=60
Or reference the environment variable directly:
build:runner-pool --remote_cache=${BAZEL_REMOTE_CACHE}
build:runner-pool --remote_upload_local_results=true
build:runner-pool --remote_timeout=60
include:
- component: $CI_SERVER_FQDN/{org}/projects/iac/attic-cache/docker-job@main
inputs:
stage: build
script: bazel build --config=runner-pool //...
The --config=runner-pool flag activates the remote cache settings. Local
builds (without the flag) are unaffected.
--remote_upload_local_results=false if you only want
cache hits without populating the cache.The Attic binary cache is available at:
https://attic.dev-cluster.example.com
Nix runners are pre-configured with this cache as a substituter. Builds automatically:
To use the Attic cache from a downstream project’s Nix runner job:
include:
- component: $CI_SERVER_FQDN/{org}/projects/iac/attic-cache/nix-job@main
inputs:
stage: build
script: nix build .#default
The nix-job component handles Attic authentication and cache configuration.
No additional setup is required in the downstream project.
To pull from the Attic cache locally (read-only, no auth required):
# Add the cache as a substituter in your nix.conf or flake.nix
extra-substituters = https://attic.dev-cluster.example.com
extra-trusted-public-keys = attic-cache:YOUR_PUBLIC_KEY_HERE
Or in flake.nix:
{
nixConfig = {
extra-substituters = [ "https://attic.dev-cluster.example.com" ];
extra-trusted-public-keys = [ "attic-cache:YOUR_PUBLIC_KEY_HERE" ];
};
}
The scripts/cache-warm.sh script pre-populates the Attic cache with
commonly-used derivations:
# Run from the attic-cache repo root
./scripts/cache-warm.sh
This is run periodically by CI to ensure cache hit rates stay high. It builds and pushes the most frequently-used dependencies across projects in the organization.
BAZEL_REMOTE_CACHE is set: echo $BAZEL_REMOTE_CACHE in your job script.--config=runner-pool.grpcurl bazel-cache.attic-cache-dev.svc.cluster.local:9092 list.--host_platform flags produce
different cache keys. Align toolchains across projects for maximum hit rate.nix-job component (not a plain docker runner).attic.dev-cluster.example.com is resolvable from the pod:
nslookup attic.dev-cluster.example.com.nix-job component handles this
automatically).nixpkgs) that differ between projects produce
different store paths. Pin inputs to the same revision for shared caching.