Skip to content

Commit b090beb

Browse files
committed
Merge #256: ci: cache gnu32 nix store
be86228 ci: cache gnu32 nix store (Sjors Provoost) Pull request description: gnu32 is by far the slowest ci job and it spends most of it's time building Nix stuff. Caching the Nix store drops subsequent runs to just 3 minutes. Not caching the other ones, because the cache is quite large and Github limits us to 10GB total. Using https://github.com/nix-community/cache-nix-action Closes #254 ACKs for top commit: ryanofsky: Code review ACK be86228. Thanks for the updates! Just suggested changes updating comments and tweaking CI_CACHE_NIX_STORE evaluation since last review. Tree-SHA512: 8c14be6f00b29f384db1f2542610a3aa42a767c3060acfae341bf52ec2e28ca9a9e043737b72f528df52491fcb455e32800018f916a8c55ffb07892e9a10e4f8
2 parents 975270b + be86228 commit b090beb

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

.github/workflows/ci.yml

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

133133
env:
134+
NIXPKGS_CHANNEL: nixos-25.05
135+
NIX_EXTRA_CONFIG: |
136+
keep-env-derivations = true
137+
keep-outputs = true
134138
NIX_EXTRA_CONFIG_ACT: |
135139
sandbox = false
136140
filter-syscalls = false
@@ -145,14 +149,33 @@ jobs:
145149
steps:
146150
- uses: actions/checkout@v5
147151

152+
- name: Determine CI configuration
153+
id: config
154+
env:
155+
CI_CONFIG: ci/configs/${{ matrix.config }}.bash
156+
run: ci/scripts/config.sh
157+
148158
- name: Install Nix
149159
uses: cachix/install-nix-action@v31 # 2025-05-27, from https://github.com/cachix/install-nix-action/tags
150160
with:
151-
nix_path: nixpkgs=channel:nixos-25.05 # latest release
161+
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/${{ steps.config.outputs.nixpkgs_rev }}.tar.gz
152162
# Act executes inside an unprivileged container (Docker or Podman),
153163
# so KVM support isn't available.
154164
enable_kvm: "${{ github.actor != 'nektos/act' }}"
155-
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+
- name: Cache Nix store
170+
if: steps.config.outputs.cache_nix_store == 'true'
171+
uses: nix-community/cache-nix-action@v7
172+
with:
173+
primary-key: nix-${{ runner.os }}-${{ matrix.config }}-${{ steps.config.outputs.nixpkgs_rev }}-${{ hashFiles('shell.nix', 'ci/patches/*.patch', format('ci/configs/{0}.bash', matrix.config)) }}
174+
restore-prefixes-first-match: |
175+
nix-${{ runner.os }}-${{ matrix.config }}-${{ steps.config.outputs.nixpkgs_rev }}-
176+
nix-${{ runner.os }}-${{ matrix.config }}-
177+
nix-${{ runner.os }}-
178+
gc-max-store-size-linux: 10G
156179

157180
- name: Run CI script
158181
env:

ci/configs/gnu32.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
CI_DESC="CI job cross-compiling to 32-bit"
22
CI_DIR=build-gnu32
3+
# Cache the heaviest Nix job to stay within GitHub's cache budget.
4+
CI_CACHE_NIX_STORE=true
35
NIX_ARGS=(
46
--arg minimal true
57
--arg crossPkgs 'import <nixpkgs> { crossSystem = { config = "i686-unknown-linux-gnu"; }; }'

ci/scripts/config.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
#
7+
# Source CI configuration and output variables needed by the workflow.
8+
9+
set -o errexit -o nounset -o pipefail -o xtrace
10+
11+
readonly SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
12+
13+
source "${SCRIPT_DIR}/ci_helpers.sh"
14+
15+
[ "${CI_CONFIG+x}" ] && source "$CI_CONFIG"
16+
17+
# Resolve the nixpkgs channel to a specific revision for use in cache keys.
18+
if [[ -n "${NIXPKGS_CHANNEL:-}" ]]; then
19+
rev="$(curl --fail --location --silent --show-error "https://channels.nixos.org/${NIXPKGS_CHANNEL}/git-revision")"
20+
test -n "${rev}"
21+
write_output_var nixpkgs_rev "${rev}"
22+
fi
23+
24+
write_output_var cache_nix_store "${CI_CACHE_NIX_STORE:-false}"

ci/scripts/run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ set -o errexit -o nounset -o pipefail -o xtrace
1111
[ "${CI_CONFIG+x}" ] && source "$CI_CONFIG"
1212

1313
nix develop --ignore-environment --keep CI_CONFIG --keep CI_CLEAN "${NIX_ARGS[@]+"${NIX_ARGS[@]}"}" -f shell.nix --command ci/scripts/ci.sh
14+
15+
# Create a GC root for the shell closure so the cache-nix-action save step
16+
# does not garbage-collect it.
17+
if [ -n "${CI_CACHE_NIX_STORE-}" ]; then
18+
nix-build shell.nix \
19+
-o "$CI_DIR/gcroot" \
20+
"${NIX_ARGS[@]+"${NIX_ARGS[@]}"}"
21+
# Verify the closure is complete so the cache-nix-action save step has
22+
# everything it needs.
23+
nix-store --query --requisites "$CI_DIR/gcroot" >/dev/null
24+
fi

0 commit comments

Comments
 (0)