Skip to content

Commit 6562d22

Browse files
committed
ci: cache gnu32 nix store
1 parent 22bec91 commit 6562d22

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ jobs:
130130
runs-on: ubuntu-latest
131131

132132
env:
133+
NIXPKGS_CHANNEL: nixos-25.05
134+
NIX_EXTRA_CONFIG: |
135+
keep-env-derivations = true
136+
keep-outputs = true
133137
NIX_EXTRA_CONFIG_ACT: |
134138
sandbox = false
135139
filter-syscalls = false
@@ -144,16 +148,62 @@ jobs:
144148
steps:
145149
- uses: actions/checkout@v5
146150

151+
- name: Resolve nixpkgs channel revision
152+
id: nixpkgs
153+
run: |
154+
rev="$(curl --fail --location --silent --show-error "https://channels.nixos.org/${NIXPKGS_CHANNEL}/git-revision")"
155+
test -n "$rev"
156+
echo "rev=$rev" >> "$GITHUB_OUTPUT"
157+
147158
- name: Install Nix
148159
uses: cachix/install-nix-action@v31 # 2025-05-27, from https://github.com/cachix/install-nix-action/tags
149160
with:
150-
nix_path: nixpkgs=channel:nixos-25.05 # latest release
161+
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/${{ steps.nixpkgs.outputs.rev }}.tar.gz
151162
# Act executes inside an unprivileged container (Docker or Podman),
152163
# so KVM support isn't available.
153164
enable_kvm: "${{ github.actor != 'nektos/act' }}"
154-
extra_nix_config: ${{ github.actor == 'nektos/act' && env.NIX_EXTRA_CONFIG_ACT || '' }}
165+
extra_nix_config: |
166+
${{ env.NIX_EXTRA_CONFIG }}
167+
${{ github.actor == 'nektos/act' && env.NIX_EXTRA_CONFIG_ACT || '' }}
168+
169+
# Cache the heaviest Nix job to stay within GitHub's cache budget while
170+
# still avoiding repeated gnu32 cross-toolchain downloads and builds.
171+
# Resolve the current channel revision once so the exact toolchain inputs
172+
# are represented in both the environment and the cache key.
173+
- name: Restore Nix store
174+
id: gnu32-nix-cache
175+
if: matrix.config == 'gnu32'
176+
uses: nix-community/cache-nix-action@v7
177+
with:
178+
primary-key: nix-${{ runner.os }}-${{ matrix.config }}-${{ steps.nixpkgs.outputs.rev }}-${{ hashFiles('shell.nix', 'ci/patches/*.patch', 'ci/configs/gnu32.bash') }}
179+
restore-prefixes-first-match: |
180+
nix-${{ runner.os }}-${{ matrix.config }}-${{ steps.nixpkgs.outputs.rev }}-
181+
nix-${{ runner.os }}-${{ matrix.config }}-
182+
nix-${{ runner.os }}-
183+
save: false
155184

156185
- name: Run CI script
157186
env:
158187
CI_CONFIG: ci/configs/${{ matrix.config }}.bash
159188
run: ci/scripts/run.sh
189+
190+
# Use an explicit save step instead of the action post-step so we only
191+
# archive the store after the build succeeded and the shell closure is
192+
# rooted against the save-time garbage collection pass.
193+
- name: Root gnu32 shell closure for cache save
194+
if: matrix.config == 'gnu32' && success() && steps.gnu32-nix-cache.outputs.hit-primary-key != 'true'
195+
run: |
196+
mkdir -p .nix-gc-roots
197+
nix-build shell.nix \
198+
-o .nix-gc-roots/gnu32-shell \
199+
--arg minimal true \
200+
--arg crossPkgs 'import <nixpkgs> { crossSystem = { config = "i686-unknown-linux-gnu"; }; }'
201+
nix-store --query --requisites .nix-gc-roots/gnu32-shell >/dev/null
202+
203+
- name: Queue Nix store save
204+
if: matrix.config == 'gnu32' && success() && steps.gnu32-nix-cache.outputs.hit-primary-key != 'true'
205+
uses: nix-community/cache-nix-action@v7
206+
with:
207+
primary-key: nix-${{ runner.os }}-${{ matrix.config }}-${{ steps.nixpkgs.outputs.rev }}-${{ hashFiles('shell.nix', 'ci/patches/*.patch', 'ci/configs/gnu32.bash') }}
208+
lookup-only: true
209+
gc-max-store-size-linux: 10G

0 commit comments

Comments
 (0)