Skip to content

Commit a47967b

Browse files
committed
feat(sccache): enable on darwin using /tmp for temp directories
1 parent c85af31 commit a47967b

File tree

3 files changed

+114
-27
lines changed

3 files changed

+114
-27
lines changed

.github/workflows/nix-build.yml

Lines changed: 76 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,43 @@ 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+
continue-on-error: true
141+
uses: mxschmitt/action-tmate@v3
142+
with:
143+
limit-access-to-actor: true
144+
detached: true
145+
install-dependencies: false
146+
- name: Configure sccache for Nix builds
147+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
148+
run: |
149+
# Ensure sccache directory exists
150+
mkdir -p /nix/var/cache/sccache
151+
# Start sccache server outside sandbox to handle all builds
152+
if command -v sccache &> /dev/null; then
153+
export SCCACHE_DIR=/nix/var/cache/sccache
154+
export SCCACHE_CACHE_SIZE=50G
155+
export SCCACHE_LOG=debug
156+
sccache --start-server || true
157+
echo "Started sccache server"
158+
sccache --show-stats
159+
fi
160+
# Update Nix configuration to allow access to sccache directory in sandbox
161+
if [ -w /etc/nix/nix.conf ]; then
162+
tee -a /etc/nix/nix.conf > /dev/null <<EOF
163+
extra-sandbox-paths = /nix/var/cache/sccache
164+
EOF
165+
fi
132166
- name: nix build
133167
if: ${{ matrix.attr != '' }}
134168
shell: bash
@@ -149,9 +183,43 @@ jobs:
149183
- name: Checkout Repo
150184
if: ${{ matrix.attr != '' }}
151185
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
186+
- name: Mount sccache disk
187+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
188+
uses: useblacksmith/stickydisk@v1
189+
with:
190+
key: ${{ github.repository }}-sccache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.cache_key }}
191+
path: /nix/var/cache/sccache
152192
- name: Install nix
153193
if: ${{ matrix.attr != '' }}
154194
uses: ./.github/actions/nix-install-self-hosted
195+
- name: Setup tmate session
196+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
197+
continue-on-error: true
198+
uses: mxschmitt/action-tmate@v3
199+
with:
200+
limit-access-to-actor: true
201+
detached: true
202+
install-dependencies: false
203+
- name: Configure sccache for Nix builds
204+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
205+
run: |
206+
# Ensure sccache directory exists
207+
mkdir -p /nix/var/cache/sccache
208+
# Start sccache server outside sandbox to handle all builds
209+
if command -v sccache &> /dev/null; then
210+
export SCCACHE_DIR=/nix/var/cache/sccache
211+
export SCCACHE_CACHE_SIZE=50G
212+
export SCCACHE_LOG=debug
213+
sccache --start-server || true
214+
echo "Started sccache server"
215+
sccache --show-stats
216+
fi
217+
# Update Nix configuration to allow access to sccache directory in sandbox
218+
if [ -w /etc/nix/nix.conf ]; then
219+
tee -a /etc/nix/nix.conf > /dev/null <<EOF
220+
extra-sandbox-paths = /nix/var/cache/sccache
221+
EOF
222+
fi
155223
- name: nix build
156224
if: ${{ matrix.attr != '' }}
157225
shell: bash
@@ -192,8 +260,8 @@ jobs:
192260
if: ${{ matrix.attr != '' && matrix.postgresql_version && matrix.runs_on.group != 'self-hosted-runners-nix' }}
193261
run: |
194262
# 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
263+
if [ -d /nix/var/cache/sccache ]; then sudo chown -R 872415232 /nix/var/cache/sccache; fi
264+
if [ -d /nix/var/cache/sccache ]; then sudo chmod -R 2777 /nix/var/cache/sccache; fi
197265
- name: nix build
198266
if: ${{ matrix.attr != '' }}
199267
shell: bash
@@ -234,8 +302,8 @@ jobs:
234302
if: ${{ matrix.attr != '' && matrix.postgresql_version && matrix.runs_on.group != 'self-hosted-runners-nix' }}
235303
run: |
236304
# 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
305+
if [ -d /nix/var/cache/sccache ]; then sudo chown -R 872415232 /nix/var/cache/sccache; fi
306+
if [ -d /nix/var/cache/sccache ]; then sudo chmod -R 2777 /nix/var/cache/sccache; fi
239307
- name: nix build
240308
if: ${{ matrix.attr != '' }}
241309
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: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,27 @@ let
165165
buildPhase = ''
166166
runHook preBuild
167167
168+
echo "Platform: ${stdenv.system}"
169+
echo "isDarwin: ${lib.boolToString stdenv.isDarwin}"
168170
171+
# Configure sccache with proper temp directories for sandbox
169172
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"
173+
if touch "/nix/var/cache/sccache/.test" 2>/dev/null && rm -f "/nix/var/cache/sccache/.test" 2>/dev/null; then
174+
echo "sccache: cache directory available and writable, enabling"
175+
${lib.optionalString stdenv.isDarwin ''
176+
# Darwin: use /tmp for temp files (allowed by sandbox-defaults.sb)
177+
export TMPDIR=/tmp
178+
export TEMP=/tmp
179+
export TEMPDIR=/tmp
180+
export TMP=/tmp
181+
''}
182+
export RUSTC_WRAPPER="${sccache}/bin/sccache"
183+
export SCCACHE_DIR="/nix/var/cache/sccache"
184+
export SCCACHE_CACHE_SIZE="50G"
185+
export SCCACHE_LOG=debug
186+
else
187+
echo "sccache: cache directory not accessible in sandbox, skipping"
188+
fi
174189
else
175190
echo "sccache: cache directory not available, skipping"
176191
fi

0 commit comments

Comments
 (0)