How to persist Flakes binary cache on CI?

I am trying to speedup nix flake build on my CI.
I can’t use cachix because all binaries have to remain inside corp network.
CI platform is a Google Cloud Build, so it’s only capable of running containerised jobs.

Here is a job plan I came up to:

  1. Download nix-cache from google cloud storage bucket to /nix-store-cache.
  2. Run docker nixpkgs/nix-flakes:latest with build instructions and /nix-store-cache mounted as a volume.
  3. Sync /nix-store-cache with storage bucket.

The problem is that I don’t understand where flakes binary cache is located. I execute docker job as follows:

docker run --rm --workdir /workspace \
-v /tmp/nix-store-cache:/nix-store-cache \
-v `pwd`:/workspace \
 /bin/bash -c '\
nix build --experimental-features "nix-command flakes" --substituters " file:///nix-cache-store" --print-build-logs ./#my-service && \
 nix --experimental-features "nix-command flakes" flake archive --to file:///nix-store-cache'

This caches flake inputs but apparently doesn’t cache myservice’s deps because each time I execute this job it recompiles every dependency without any noticeable speedup.
Should I also cache /nix/store? This looks semantically wrong because /nix/store is not a cache, furthermore, it’s harder to extract from docker image because it’s already prepopulated in a base nixpkgs/nix-flakes image and I can’t just mount /nix/store from some host directory.

1 Like

I am trying to do the same thing, also on GCP. @tailrecursive Did you end up figuring it out?