Skip to content

Commit 737ea24

Browse files
committed
fix(sccache): disable on darwin due to sandbox temp directory restrictions
1 parent 1df6dac commit 737ea24

4 files changed

Lines changed: 108 additions & 31 deletions

File tree

.github/workflows/nix-build.yml

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ jobs:
5959
if: ${{ matrix.attr != '' && matrix.postgresql_version && matrix.runs_on.group != 'self-hosted-runners-nix' }}
6060
run: |
6161
# With auto-allocate-uids, UID 872415232 (0x34000000) maps to nixbld inside sandbox
62-
sudo chown -R 872415232 /nix/var/cache/sccache
63-
sudo chmod -R 2777 /nix/var/cache/sccache
62+
if [ -d /nix/var/cache/sccache ]; then sudo chown -R 872415232 /nix/var/cache/sccache; fi
63+
if [ -d /nix/var/cache/sccache ]; then sudo chmod -R 2777 /nix/var/cache/sccache; fi
6464
- name: nix build
6565
if: ${{ matrix.attr != '' }}
6666
shell: bash
@@ -104,8 +104,8 @@ jobs:
104104
if: ${{ matrix.attr != '' && matrix.postgresql_version && matrix.runs_on.group != 'self-hosted-runners-nix' }}
105105
run: |
106106
# With auto-allocate-uids, UID 872415232 (0x34000000) maps to nixbld inside sandbox
107-
sudo chown -R 872415232 /nix/var/cache/sccache
108-
sudo chmod -R 2777 /nix/var/cache/sccache
107+
if [ -d /nix/var/cache/sccache ]; then sudo chown -R 872415232 /nix/var/cache/sccache; fi
108+
if [ -d /nix/var/cache/sccache ]; then sudo chmod -R 2777 /nix/var/cache/sccache; fi
109109
- name: nix build
110110
if: ${{ matrix.attr != '' }}
111111
shell: bash
@@ -126,9 +126,41 @@ 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: Setup tmate session
139+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
140+
uses: mxschmitt/action-tmate@v3
141+
with:
142+
limit-access-to-actor: true
143+
detached: true
144+
- name: Configure sccache for Nix builds
145+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
146+
run: |
147+
# Ensure sccache directory exists
148+
mkdir -p /nix/var/cache/sccache
149+
# Start sccache server outside sandbox to handle all builds
150+
if command -v sccache &> /dev/null; then
151+
export SCCACHE_DIR=/nix/var/cache/sccache
152+
export SCCACHE_CACHE_SIZE=50G
153+
export SCCACHE_LOG=debug
154+
sccache --start-server || true
155+
echo "Started sccache server"
156+
sccache --show-stats
157+
fi
158+
# Update Nix configuration to allow access to sccache directory in sandbox
159+
if [ -w /etc/nix/nix.conf ]; then
160+
tee -a /etc/nix/nix.conf > /dev/null <<EOF
161+
extra-sandbox-paths = /nix/var/cache/sccache
162+
EOF
163+
fi
132164
- name: nix build
133165
if: ${{ matrix.attr != '' }}
134166
shell: bash
@@ -149,9 +181,41 @@ jobs:
149181
- name: Checkout Repo
150182
if: ${{ matrix.attr != '' }}
151183
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
184+
- name: Mount sccache disk
185+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
186+
uses: useblacksmith/stickydisk@v1
187+
with:
188+
key: ${{ github.repository }}-sccache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.cache_key }}
189+
path: /nix/var/cache/sccache
152190
- name: Install nix
153191
if: ${{ matrix.attr != '' }}
154192
uses: ./.github/actions/nix-install-self-hosted
193+
- name: Setup tmate session
194+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
195+
uses: mxschmitt/action-tmate@v3
196+
with:
197+
limit-access-to-actor: true
198+
detached: true
199+
- name: Configure sccache for Nix builds
200+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
201+
run: |
202+
# Ensure sccache directory exists
203+
mkdir -p /nix/var/cache/sccache
204+
# Start sccache server outside sandbox to handle all builds
205+
if command -v sccache &> /dev/null; then
206+
export SCCACHE_DIR=/nix/var/cache/sccache
207+
export SCCACHE_CACHE_SIZE=50G
208+
export SCCACHE_LOG=debug
209+
sccache --start-server || true
210+
echo "Started sccache server"
211+
sccache --show-stats
212+
fi
213+
# Update Nix configuration to allow access to sccache directory in sandbox
214+
if [ -w /etc/nix/nix.conf ]; then
215+
tee -a /etc/nix/nix.conf > /dev/null <<EOF
216+
extra-sandbox-paths = /nix/var/cache/sccache
217+
EOF
218+
fi
155219
- name: nix build
156220
if: ${{ matrix.attr != '' }}
157221
shell: bash
@@ -192,8 +256,8 @@ jobs:
192256
if: ${{ matrix.attr != '' && matrix.postgresql_version && matrix.runs_on.group != 'self-hosted-runners-nix' }}
193257
run: |
194258
# With auto-allocate-uids, UID 872415232 (0x34000000) maps to nixbld inside sandbox
195-
sudo chown -R 872415232 /nix/var/cache/sccache
196-
sudo chmod -R 2777 /nix/var/cache/sccache
259+
if [ -d /nix/var/cache/sccache ]; then sudo chown -R 872415232 /nix/var/cache/sccache; fi
260+
if [ -d /nix/var/cache/sccache ]; then sudo chmod -R 2777 /nix/var/cache/sccache; fi
197261
- name: nix build
198262
if: ${{ matrix.attr != '' }}
199263
shell: bash
@@ -234,8 +298,8 @@ jobs:
234298
if: ${{ matrix.attr != '' && matrix.postgresql_version && matrix.runs_on.group != 'self-hosted-runners-nix' }}
235299
run: |
236300
# With auto-allocate-uids, UID 872415232 (0x34000000) maps to nixbld inside sandbox
237-
sudo chown -R 872415232 /nix/var/cache/sccache
238-
sudo chmod -R 2777 /nix/var/cache/sccache
301+
if [ -d /nix/var/cache/sccache ]; then sudo chown -R 872415232 /nix/var/cache/sccache; fi
302+
if [ -d /nix/var/cache/sccache ]; then sudo chmod -R 2777 /nix/var/cache/sccache; fi
239303
- name: nix build
240304
if: ${{ matrix.attr != '' }}
241305
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: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,23 @@ let
165165
buildPhase = ''
166166
runHook preBuild
167167
168-
169-
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"
168+
echo "Platform: ${stdenv.system}"
169+
echo "isDarwin: ${lib.boolToString stdenv.isDarwin}"
170+
171+
# sccache doesn't work in Nix Darwin sandbox due to temporary directory restrictions
172+
if [[ "${lib.boolToString stdenv.isDarwin}" != "true" && -d "/nix/var/cache/sccache" && -w "/nix/var/cache/sccache" ]]; then
173+
# Test if sccache can actually write to the directory (sandbox check)
174+
if touch "/nix/var/cache/sccache/.test" 2>/dev/null && rm -f "/nix/var/cache/sccache/.test" 2>/dev/null; then
175+
echo "sccache: cache directory available and writable in sandbox, enabling"
176+
export RUSTC_WRAPPER="${sccache}/bin/sccache"
177+
export SCCACHE_DIR="/nix/var/cache/sccache"
178+
export SCCACHE_CACHE_SIZE="50G"
179+
export SCCACHE_LOG=debug
180+
else
181+
echo "sccache: cache directory not accessible in sandbox (needs extra-sandbox-paths configuration), skipping"
182+
fi
174183
else
175-
echo "sccache: cache directory not available, skipping"
184+
echo "sccache: not available or running on Darwin, skipping"
176185
fi
177186
178187
echo "Executing cargo-pgrx buildPhase"

nix/packages/github-matrix/github_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def main() -> None:
311311

312312
args = parser.parse_args()
313313

314-
max_workers: int = os.cpu_count() or 1
314+
max_workers: int = int(os.cpu_count() / 2) or 1
315315

316316
cmd = build_nix_eval_command(max_workers, args.flake_outputs)
317317

0 commit comments

Comments
 (0)