Skip to content

Commit e734375

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

1 file changed

Lines changed: 50 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 50 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,60 @@ jobs:
144148
steps:
145149
- uses: actions/checkout@v5
146150

151+
- name: Resolve nixpkgs channel revision
152+
id: nixpkgs
153+
run: |
154+
rev="$(curl --fail --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/restore@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 }}-
155183
156184
- name: Run CI script
157185
env:
158186
CI_CONFIG: ci/configs/${{ matrix.config }}.bash
159187
run: ci/scripts/run.sh
188+
189+
# Use an explicit save step instead of the action post-step so we only
190+
# archive the store after the build succeeded and the shell closure is
191+
# rooted against the save-time garbage collection pass.
192+
- name: Root gnu32 shell closure for cache save
193+
if: matrix.config == 'gnu32' && success() && steps.gnu32-nix-cache.outputs.hit-primary-key != 'true'
194+
run: |
195+
mkdir -p .nix-gc-roots
196+
nix-build shell.nix \
197+
-o .nix-gc-roots/gnu32-shell \
198+
--arg minimal true \
199+
--arg crossPkgs 'import <nixpkgs> { crossSystem = { config = "i686-unknown-linux-gnu"; }; }'
200+
nix-store --query --requisites .nix-gc-roots/gnu32-shell >/dev/null
201+
202+
- name: Save Nix store
203+
if: matrix.config == 'gnu32' && success() && steps.gnu32-nix-cache.outputs.hit-primary-key != 'true'
204+
uses: nix-community/cache-nix-action/save@v7
205+
with:
206+
primary-key: ${{ steps.gnu32-nix-cache.outputs.primary-key }}
207+
gc-max-store-size-linux: 10G

0 commit comments

Comments
 (0)