Skip to content

Commit 44ed9c7

Browse files
committed
fix: enable sccache on Darwin with isolated temp directory
Use SCCACHE_NO_DAEMON=1 and redirect TMPDIR to sccache cache dir to avoid cross-sandbox permission errors on Darwin
1 parent c2f6188 commit 44ed9c7

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

nix/cargo-pgrx/buildPgrxExtension.nix

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,26 @@ let
165165
buildPhase = ''
166166
runHook preBuild
167167
168-
${lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
169-
if [[ -d "/nix/var/cache/sccache" && -w "/nix/var/cache/sccache" ]]; then
170-
# Test if sccache can actually write to the directory (sandbox check)
171-
if touch "/nix/var/cache/sccache/.test" 2>/dev/null && rm -f "/nix/var/cache/sccache/.test" 2>/dev/null; then
172-
echo "sccache: cache directory available and writable in sandbox, enabling"
173-
export RUSTC_WRAPPER="${sccache}/bin/sccache"
174-
export SCCACHE_DIR="/nix/var/cache/sccache"
175-
export SCCACHE_CACHE_SIZE="50G"
176-
else
177-
echo "sccache: cache directory not accessible in sandbox (needs extra-sandbox-paths configuration), skipping"
178-
fi
168+
if [[ -d "/nix/var/cache/sccache" && -w "/nix/var/cache/sccache" ]]; then
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+
${lib.optionalString stdenv.hostPlatform.isDarwin ''
176+
# On Darwin, sccache daemon mode causes cross-sandbox permission issues
177+
# Use no-daemon and redirect temp files to shared cache directory
178+
export SCCACHE_NO_DAEMON=1
179+
export TMPDIR="/nix/var/cache/sccache/tmp"
180+
mkdir -p "$TMPDIR"
181+
''}
179182
else
180-
echo "sccache: cache directory not available, skipping"
183+
echo "sccache: cache directory not accessible in sandbox (needs extra-sandbox-paths configuration), skipping"
181184
fi
182-
''}
185+
else
186+
echo "sccache: cache directory not available, skipping"
187+
fi
183188
184189
echo "Executing cargo-pgrx buildPhase"
185190
${preBuildAndTest}

0 commit comments

Comments
 (0)