Skip to content

Commit 0e99c8b

Browse files
refactor(ci): align setup-nix action with infra reference implementation
Replace custom setup-nix action with standardized version from infra: - Use nix-quick-install-action for all installs (removes DeterminateSystems dependency) - Add nix-community/cache-nix-action for GitHub Actions caching on Linux - Change hatchet-protocol from 'rampage' to 'carve' (less aggressive) - Add pinned SHA commits for all actions (security best practice) - Standardize input parameters and add cache outputs - Simplify cachix integration with cachix-action instead of sops/shell scripts
1 parent e1dafdf commit 0e99c8b

File tree

1 file changed

+82
-56
lines changed

1 file changed

+82
-56
lines changed

.github/actions/setup-nix/action.yml

Lines changed: 82 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,86 @@
11
name: setup-nix
2-
description: Setup Nix with optional disk space optimization and cachix binary cache configuration
2+
description: setup nix using nothing-but-nix pattern with space reclamation and github actions cache
33

44
inputs:
55
installer:
66
description: |
7-
Nix installation strategy:
8-
- 'full' (default): Aggressive disk cleanup + DeterminateSystems installer
9-
- 'quick': Lightweight install with nixbuild/nix-quick-install-action
7+
nix installation strategy:
8+
- 'full' (default): space reclamation + cache + cachix for builds
9+
- 'quick': minimal install for simple tasks (no space reclamation, no caching overhead)
1010
type: string
1111
required: false
1212
default: full
1313
system:
14-
description: Nix system to configure (e.g., x86_64-linux, aarch64-darwin)
14+
description: nix system to configure (e.g., x86_64-linux, aarch64-darwin)
1515
type: string
16-
required: false
17-
default: x86_64-linux
18-
extra-conf:
19-
description: Additional nix.conf configuration
16+
required: true
17+
sandbox:
18+
description: enable nix sandbox builds
19+
type: string
20+
default: "true"
21+
cache-key:
22+
description: primary cache key (auto-generated from nix files if not provided)
2023
type: string
2124
required: false
22-
default: system-features = nixos-test benchmark big-parallel kvm
23-
setup-cachix:
24-
description: Setup cachix binary cache after Nix installation (requires SOPS_AGE_KEY in env)
25+
default: ""
26+
gc-max-store-size-linux:
27+
description: max nix store size on linux before garbage collection (e.g., 5G, 10G)
28+
type: string
29+
default: "5G"
30+
gc-max-store-size-macos:
31+
description: max nix store size on macos before garbage collection (e.g., 5G, 10G)
32+
type: string
33+
default: "5G"
34+
enable-cachix:
35+
description: enable cachix binary cache
2536
type: boolean
26-
required: false
2737
default: false
28-
cachix-auth:
29-
description: Authenticate with cachix for pushing (requires setup-cachix=true)
30-
type: boolean
38+
cachix-name:
39+
description: cachix cache name
40+
type: string
41+
required: false
42+
cachix-auth-token:
43+
description: cachix auth token
44+
type: string
3145
required: false
46+
cachix-skip-push:
47+
description: skip pushing to cachix (read-only)
48+
type: boolean
3249
default: false
3350

51+
outputs:
52+
cache-hit:
53+
description: whether the primary cache key was hit
54+
value: ${{ steps.cache.outputs.hit-primary-key }}
55+
cache-key:
56+
description: the cache key that was used
57+
value: ${{ steps.cache.outputs.primary-key }}
58+
3459
runs:
3560
using: composite
3661
steps:
37-
# Full installer: Aggressive disk cleanup + DeterminateSystems
38-
- name: Reclaim disk space (Linux)
62+
- name: reclaim space (linux)
3963
if: runner.os == 'Linux' && inputs.installer == 'full'
40-
uses: wimpysworld/nothing-but-nix@main
64+
uses: wimpysworld/nothing-but-nix@10c936d9e46521bf923f75458e0cbd4fa309300d # ratchet:wimpysworld/nothing-but-nix@main
4165
with:
42-
hatchet-protocol: rampage
66+
hatchet-protocol: carve
67+
nix-permission-edict: true
4368

44-
- name: Reclaim disk space (macOS)
69+
- name: reclaim space (darwin)
4570
if: runner.os == 'macOS' && inputs.installer == 'full'
4671
shell: bash
4772
run: |
48-
echo "::group::Disk space before cleanup"
73+
echo "::group::disk space (before)"
4974
sudo df -h
5075
echo "::endgroup::"
5176
52-
echo "::group::Disable Spotlight indexing"
77+
echo "::group::disable mds"
5378
sudo mdutil -i off -a || echo "mdutil failed"
5479
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist \
55-
|| echo "launchctl unload failed"
80+
|| echo "launchctl unload failed"
5681
echo "::endgroup::"
5782
58-
echo "Starting background cleanup to reclaim disk space..."
83+
echo "Background space expansion started. /nix will grow as space becomes available."
5984
sudo rm -rf \
6085
/Applications/Xcode_* \
6186
/Library/Developer/CoreSimulator \
@@ -67,44 +92,45 @@ runs:
6792
/Users/runner/Library/Developer/CoreSimulator \
6893
/Users/runner/hostedtoolcache &
6994
70-
- name: Install Nix (DeterminateSystems)
71-
if: inputs.installer == 'full'
72-
uses: DeterminateSystems/nix-installer-action@main
95+
- name: install nix
96+
uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # ratchet:nixbuild/nix-quick-install-action@v34
7397
with:
74-
extra-conf: |
98+
nix_conf: |
99+
sandbox = ${{ inputs.sandbox }}
75100
system = ${{ inputs.system }}
76-
${{ inputs.extra-conf }}
101+
keep-env-derivations = true
102+
keep-outputs = true
77103
78-
# Quick installer: Lightweight nixbuild/nix-quick-install-action
79-
- name: Install Nix (Quick Install)
80-
if: inputs.installer == 'quick'
81-
uses: nixbuild/nix-quick-install-action@master
104+
- name: setup cache
105+
if: runner.os == 'Linux' && inputs.installer == 'full'
106+
id: cache
107+
uses: nix-community/cache-nix-action@135667ec418502fa5a3598af6fb9eb733888ce6a # ratchet:nix-community/cache-nix-action@v6
108+
with:
109+
primary-key: ${{ inputs.cache-key != '' && inputs.cache-key || format('nix-{0}-{1}', runner.os, hashFiles('**/*.nix', '**/flake.lock')) }}
110+
restore-prefixes-first-match: ${{ format('nix-{0}-', runner.os) }}
111+
gc-max-store-size-linux: ${{ inputs.gc-max-store-size-linux }}
112+
gc-max-store-size-macos: ${{ inputs.gc-max-store-size-macos }}
113+
purge: true
114+
purge-prefixes: ${{ format('nix-{0}-', runner.os) }}
115+
purge-created: 0
116+
purge-last-accessed: 0
117+
purge-primary-key: never
82118

83-
- name: Report disk space (macOS post-cleanup)
119+
- name: setup cachix
120+
if: inputs.enable-cachix
121+
uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad # ratchet:cachix/cachix-action@v16
122+
continue-on-error: true
123+
with:
124+
name: ${{ inputs.cachix-name }}
125+
authToken: ${{ inputs.cachix-auth-token }}
126+
skipPush: ${{ inputs.cachix-skip-push }}
127+
128+
- name: post setup-nix
84129
if: runner.os == 'macOS' && inputs.installer == 'full'
85-
uses: srz-zumix/post-run-action@v2
130+
uses: srz-zumix/post-run-action@2bf288bc024acd0341914f792a811080ebd0f252 # ratchet:srz-zumix/post-run-action@v2
86131
with:
87132
shell: bash -e {0}
88133
post-run: |
89-
echo "::group::Disk space after workflow"
134+
echo "::group::disk space (after)"
90135
sudo df -h
91136
echo "::endgroup::"
92-
93-
- name: Setup and authenticate cachix
94-
if: inputs.setup-cachix == 'true' && inputs.cachix-auth == 'true'
95-
shell: bash
96-
run: |
97-
nix develop -c sops exec-env vars/shared.yaml '
98-
cachix authtoken "$CACHIX_AUTH_TOKEN"
99-
cachix use "$CACHIX_CACHE_NAME"
100-
cachix use nix-community
101-
'
102-
103-
- name: Setup cachix for binary cache
104-
if: inputs.setup-cachix == 'true' && inputs.cachix-auth != 'true'
105-
shell: bash
106-
run: |
107-
nix develop -c sops exec-env vars/shared.yaml '
108-
cachix use "$CACHIX_CACHE_NAME"
109-
cachix use nix-community
110-
'

0 commit comments

Comments
 (0)