From d3a64dc989c22ada53ff380a530b1c95e205dc2a Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Fri, 24 Jan 2025 16:58:26 +0100 Subject: [PATCH] zig: fix darwin SDK lookup --- pkgs/development/compilers/zig/generic.nix | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/pkgs/development/compilers/zig/generic.nix b/pkgs/development/compilers/zig/generic.nix index 3da36c083bd3b..bdd10c9cfbda7 100644 --- a/pkgs/development/compilers/zig/generic.nix +++ b/pkgs/development/compilers/zig/generic.nix @@ -7,6 +7,7 @@ , zlib , coreutils , callPackage +, xcbuild , ... }: @@ -50,15 +51,25 @@ stdenv.mkDerivation (finalAttrs: { export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-cache"; ''; - # Zig's build looks at /usr/bin/env to find dynamic linking info. This doesn't - # work in Nix's sandbox. Use env from our coreutils instead. - postPatch = if lib.versionAtLeast args.version "0.12" then '' - substituteInPlace lib/std/zig/system.zig \ - --replace "/usr/bin/env" "${coreutils}/bin/env" - '' else '' - substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \ - --replace-fail "/usr/bin/env" "${coreutils}/bin/env" - ''; + postPatch = + # Zig's build looks at /usr/bin/env to find dynamic linking info. This doesn't + # work in Nix's sandbox. Use env from our coreutils instead. + (if lib.versionAtLeast args.version "0.12" then '' + substituteInPlace lib/std/zig/system.zig \ + --replace "/usr/bin/env" "${coreutils}/bin/env" + '' else '' + substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \ + --replace-fail "/usr/bin/env" "${coreutils}/bin/env" + '') + # Zig tries to access xcrun at the absolute system path to query the macOS SDK + # location, which does not work in the darwin sandbox. + # We can just provide "xcrun" instead as it is part of the darwin stdenv. + # Upstream issue: https://github.com/ziglang/zig/issues/22600 + + lib.optionalString stdenv.hostPlatform.isDarwin '' + substituteInPlace lib/std/zig/system/darwin.zig \ + --replace-fail /usr/bin/xcrun xcrun \ + --replace-fail /usr/bin/xcode-select '${lib.getExe' xcbuild "xcode-select"}' + ''; doInstallCheck = true; installCheckPhase = ''