Skip to content

Commit 846c792

Browse files
committed
feat: enable sccache for Darwin with sandbox write check
Configure sccache on aarch64-darwin self-hosted runners with persistent cache disk mounting and Nix sandbox access via extra-sandbox-paths. Add actual write test in buildPgrxExtension to verify sandbox access before enabling sccache. Use jfroche/nix-eval-jobs fork with its own nixpkgs to avoid lowdown compatibility issues. Requires deploying sccache configuration to runners via self-hosted-nix-builders repo.
1 parent 17cb841 commit 846c792

3 files changed

Lines changed: 62 additions & 20 deletions

File tree

.github/workflows/nix-build.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,26 @@ jobs:
126126
- name: Checkout Repo
127127
if: ${{ matrix.attr != '' }}
128128
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
129+
- name: Mount sccache disk
130+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
131+
uses: useblacksmith/stickydisk@v1
132+
with:
133+
key: ${{ github.repository }}-sccache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.cache_key }}
134+
path: /nix/var/cache/sccache
129135
- name: Install nix
130136
if: ${{ matrix.attr != '' }}
131137
uses: ./.github/actions/nix-install-self-hosted
138+
- name: Configure sccache for Nix builds
139+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
140+
run: |
141+
# Ensure sccache directory exists
142+
mkdir -p /nix/var/cache/sccache
143+
# Update Nix configuration to allow access to sccache directory in sandbox
144+
if [ -w /etc/nix/nix.conf ]; then
145+
tee -a /etc/nix/nix.conf > /dev/null <<EOF
146+
extra-sandbox-paths = /nix/var/cache/sccache
147+
EOF
148+
fi
132149
- name: nix build
133150
if: ${{ matrix.attr != '' }}
134151
shell: bash
@@ -149,9 +166,26 @@ jobs:
149166
- name: Checkout Repo
150167
if: ${{ matrix.attr != '' }}
151168
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
169+
- name: Mount sccache disk
170+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
171+
uses: useblacksmith/stickydisk@v1
172+
with:
173+
key: ${{ github.repository }}-sccache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.cache_key }}
174+
path: /nix/var/cache/sccache
152175
- name: Install nix
153176
if: ${{ matrix.attr != '' }}
154177
uses: ./.github/actions/nix-install-self-hosted
178+
- name: Configure sccache for Nix builds
179+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
180+
run: |
181+
# Ensure sccache directory exists
182+
mkdir -p /nix/var/cache/sccache
183+
# Update Nix configuration to allow access to sccache directory in sandbox
184+
if [ -w /etc/nix/nix.conf ]; then
185+
tee -a /etc/nix/nix.conf > /dev/null <<EOF
186+
extra-sandbox-paths = /nix/var/cache/sccache
187+
EOF
188+
fi
155189
- name: nix build
156190
if: ${{ matrix.attr != '' }}
157191
shell: bash

flake.lock

Lines changed: 19 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/cargo-pgrx/buildPgrxExtension.nix

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,16 @@ let
165165
buildPhase = ''
166166
runHook preBuild
167167
168-
169168
if [[ -d "/nix/var/cache/sccache" && -w "/nix/var/cache/sccache" ]]; then
170-
echo "sccache: cache directory available, enabling"
171-
export RUSTC_WRAPPER="${sccache}/bin/sccache"
172-
export SCCACHE_DIR="/nix/var/cache/sccache"
173-
export SCCACHE_CACHE_SIZE="50G"
169+
# Test if sccache can actually write to the directory (sandbox check)
170+
if touch "/nix/var/cache/sccache/.test" 2>/dev/null && rm -f "/nix/var/cache/sccache/.test" 2>/dev/null; then
171+
echo "sccache: cache directory available and writable in sandbox, enabling"
172+
export RUSTC_WRAPPER="${sccache}/bin/sccache"
173+
export SCCACHE_DIR="/nix/var/cache/sccache"
174+
export SCCACHE_CACHE_SIZE="50G"
175+
else
176+
echo "sccache: cache directory not accessible in sandbox (needs extra-sandbox-paths configuration), skipping"
177+
fi
174178
else
175179
echo "sccache: cache directory not available, skipping"
176180
fi

0 commit comments

Comments
 (0)