zig: move ZIG_GLOBAL_CACHE_DIR setup to configurePhase

This allows users to put zig in their `mkShell` without ending up with a
ZIG_GLOBAL_CACHE_DIR value set that points back to a location that only
would exist in the sandbox.
This commit is contained in:
Jared Baur
2026-01-12 09:02:04 -08:00
parent 5bfbbc27f6
commit e20232eab6
3 changed files with 15 additions and 3 deletions
+4
View File
@@ -32,6 +32,10 @@ stdenv.mkDerivation {
The variables below are exclusive to `zig`. The variables below are exclusive to `zig`.
#### `dontUseZigConfigure` {#dont-use-zig-configure}
Disables using `zigConfigurePhase`.
#### `dontUseZigBuild` {#dont-use-zig-build} #### `dontUseZigBuild` {#dont-use-zig-build}
Disables using `zigBuildPhase`. Disables using `zigBuildPhase`.
+3
View File
@@ -2762,6 +2762,9 @@
"index.html#zig-exclusive-variables", "index.html#zig-exclusive-variables",
"index.html#zig-hook-exclusive-variables" "index.html#zig-hook-exclusive-variables"
], ],
"dont-use-zig-configure": [
"index.html#dont-use-zig-configure"
],
"dont-use-zig-build": [ "dont-use-zig-build": [
"index.html#dont-use-zig-build" "index.html#dont-use-zig-build"
], ],
+8 -3
View File
@@ -4,9 +4,13 @@
readonly zigDefaultCpuFlag=@zig_default_cpu_flag@ readonly zigDefaultCpuFlag=@zig_default_cpu_flag@
readonly zigDefaultOptimizeFlag=@zig_default_optimize_flag@ readonly zigDefaultOptimizeFlag=@zig_default_optimize_flag@
function zigSetGlobalCacheDir { function zigConfigurePhase {
runHook preConfigure
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) ZIG_GLOBAL_CACHE_DIR=$(mktemp -d)
export ZIG_GLOBAL_CACHE_DIR export ZIG_GLOBAL_CACHE_DIR
runHook postConfigure
} }
function zigBuildPhase { function zigBuildPhase {
@@ -97,8 +101,9 @@ function zigInstallPhase {
runHook postInstall runHook postInstall
} }
# shellcheck disable=SC2154 if [ -z "${dontUseZigConfigure-}" ] && [ -z "${configurePhase-}" ]; then
addEnvHooks "$hostOffset" zigSetGlobalCacheDir configurePhase=zigConfigurePhase
fi
if [ -z "${dontUseZigBuild-}" ] && [ -z "${buildPhase-}" ]; then if [ -z "${dontUseZigBuild-}" ] && [ -z "${buildPhase-}" ]; then
buildPhase=zigBuildPhase buildPhase=zigBuildPhase