From 29b8e889c231ada2d34da84ebd3ec94707e1fcc4 Mon Sep 17 00:00:00 2001 From: emmanuelist Date: Wed, 19 Aug 2026 00:05:14 +0100 Subject: [PATCH] Bound nix cache size in CI magic-nix-cache-action writes one GitHub cache entry per nix store path, which churns through the Actions cache API and leaves over a thousand entries behind. Swap it for nix-community/cache-nix-action, which keeps the store as a single bounded entry per job, purging all but the newest. Point the rust jobs at the shared setup-nix action too, rather than repeating the install and cache steps inline, so there is one place to change this. Keys are scoped by `github.job` because jobs realise different store closures, and job ids are unique across the workflows that set nix up. Note this reduces entry count and churn but does not by itself free the cache quota: Swatinem/rust-cache accounts for 9.32 GiB of the 10 GB against cache-nix-action's 0.59 GiB. See #1131 for the numbers. --- .github/actions/setup-nix/action.yml | 10 ++++++++-- .github/workflows/rust.yml | 24 ++++++------------------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/.github/actions/setup-nix/action.yml b/.github/actions/setup-nix/action.yml index d705a5b69..c1c3e5bf1 100644 --- a/.github/actions/setup-nix/action.yml +++ b/.github/actions/setup-nix/action.yml @@ -9,6 +9,12 @@ runs: - name: Install nix uses: DeterminateSystems/determinate-nix-action@main - name: Use nix cache - uses: DeterminateSystems/magic-nix-cache-action@main + uses: nix-community/cache-nix-action@v7 with: - use-flakehub: false + primary-key: nix-${{ runner.os }}-${{ github.job }}-${{ hashFiles('flake.nix', 'flake.lock') }} + restore-prefixes-first-match: nix-${{ runner.os }}-${{ github.job }}- + gc-max-store-size: 1G + purge: true + purge-prefixes: nix-${{ runner.os }}-${{ github.job }}- + purge-created: 0 + purge-primary-key: never diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3cd50ce6d..e9dde3148 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -27,12 +27,8 @@ jobs: # The toolchain must be specified manually, as this action ignores the rust-toolchain override # https://github.com/dtolnay/rust-toolchain?tab=readme-ov-file#inputs toolchain: ${{ matrix.rust }} - - name: "Install nix" - uses: DeterminateSystems/determinate-nix-action@main - - name: "Use nix cache" - uses: DeterminateSystems/magic-nix-cache-action@main - with: - use-flakehub: false + - name: Set up nix + uses: ./.github/actions/setup-nix - name: "Add nginxWithStream to PATH" run: | # This is necessary for payjoin-mailroom integration tests @@ -49,12 +45,8 @@ jobs: uses: actions/checkout@v6 - name: "Use cache" uses: Swatinem/rust-cache@v2 - - name: "Install nix" - uses: DeterminateSystems/determinate-nix-action@main - - name: "Use nix cache" - uses: DeterminateSystems/magic-nix-cache-action@main - with: - use-flakehub: false + - name: Set up nix + uses: ./.github/actions/setup-nix - name: "Run code linting" run: nix develop -c ./contrib/lint.sh - name: "Run documentation linting" @@ -77,12 +69,8 @@ jobs: - name: "Install toolchain" # rust-cache usage with stable Rust is most effective, as a cache is tied to the Rust version uses: dtolnay/rust-toolchain@stable - - name: "Install nix" - uses: DeterminateSystems/determinate-nix-action@main - - name: "Use nix cache" - uses: DeterminateSystems/magic-nix-cache-action@main - with: - use-flakehub: false + - name: Set up nix + uses: ./.github/actions/setup-nix - name: "Add nginxWithStream to PATH" run: | # This is necessary for payjoin-mailroom integration tests