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
0 commit comments