name: Restore Nix cache description: | Restore /nix from the shared CI cache and runs garbage collection before storing if save is set to true. inputs: save: description: Whether this job should save the cache after running. required: false default: "false" outputs: cache-key-hash: description: > Hash of the Nix inputs (flake, toolchain, lockfiles) that key the /nix cache. Dependent caches (e.g. the Rust build cache) should fold this into their key so they are invalidated whenever the Nix-provided toolchain changes. value: ${{ steps.compute-key.outputs.hash }} runs: using: composite steps: - name: Compute Nix cache key hash id: compute-key shell: bash run: echo "hash=${{ hashFiles('flake.nix', 'flake.lock', 'nix/**', 'rust-toolchain.toml', 'Cargo.lock') }}" >> "$GITHUB_OUTPUT" - name: Restore /nix from cache uses: nix-community/cache-nix-action@7df957e333c1e5da7721f60227dbba6d06080569 # v7.0.2 with: primary-key: nix-${{ runner.os }}-ci-${{ steps.compute-key.outputs.hash }} restore-prefixes-first-match: nix-${{ runner.os }}-ci- save: ${{ inputs.save }} # Target store size of 0 means always run garbage collection. # Note that pinning step below prevents the usable cache to be cleaned. gc-max-store-size: 0 - name: Pin dev-shell closure as GC root if: inputs.save == 'true' shell: bash # `--profile` registers the dev-shell closure as an indirect GC root, # so the pre-upload garbage collection keeps it (and its dependencies) # while dropping everything else. run: nix develop --profile "$RUNNER_TEMP/ci-devshell" --command true