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:
- Download nix-cache from google cloud storage bucket to
- Run docker
nixpkgs/nix-flakes:latestwith build instructions and
/nix-store-cachemounted as a volume.
/nix-store-cachewith 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 \ nixpkgs/nix-flakes:latest\ /bin/bash -c '\ nix build --experimental-features "nix-command flakes" --substituters "https://cache.nixos.org 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.