From 9624688f7e5da273448b9ff16632b96f2dfbadbd Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Fri, 24 Jan 2025 16:27:04 +0100 Subject: [PATCH 1/4] zig_0_11: fix darwin SDK lookup --- .../compilers/zig/0.11/default.nix | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkgs/development/compilers/zig/0.11/default.nix b/pkgs/development/compilers/zig/0.11/default.nix index 91e753dbf0fed..b0b9292da617e 100644 --- a/pkgs/development/compilers/zig/0.11/default.nix +++ b/pkgs/development/compilers/zig/0.11/default.nix @@ -9,6 +9,7 @@ stdenv, testers, zlib, + xcbuild, }: stdenv.mkDerivation (finalAttrs: { @@ -58,12 +59,22 @@ stdenv.mkDerivation (finalAttrs: { strictDeps = true; - # 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 = '' - substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \ - --replace "/usr/bin/env" "${lib.getExe' coreutils "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. + '' + substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \ + --replace "/usr/bin/env" "${lib.getExe' coreutils "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"}' + ''; postBuild = '' stage3/bin/zig run ../tools/docgen.zig -- ../doc/langref.html.in langref.html --zig $PWD/stage3/bin/zig From d9ba556072dc2f352b36b8b6176249cbf403c395 Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Fri, 24 Jan 2025 16:23:39 +0100 Subject: [PATCH 2/4] zig_0_12: fix darwin SDK lookup --- .../compilers/zig/0.12/default.nix | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkgs/development/compilers/zig/0.12/default.nix b/pkgs/development/compilers/zig/0.12/default.nix index f359140df234b..a1d77d5cf4d0a 100644 --- a/pkgs/development/compilers/zig/0.12/default.nix +++ b/pkgs/development/compilers/zig/0.12/default.nix @@ -9,6 +9,7 @@ stdenv, testers, zlib, + xcbuild, }: stdenv.mkDerivation (finalAttrs: { @@ -70,12 +71,22 @@ stdenv.mkDerivation (finalAttrs: { # https://github.com/NixOS/nixpkgs/issues/317055#issuecomment-2148438395 strictDeps = !stdenv.cc.isClang; - # 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 = '' - substituteInPlace lib/std/zig/system.zig \ - --replace "/usr/bin/env" "${lib.getExe' coreutils "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. + '' + substituteInPlace lib/std/zig/system.zig \ + --replace "/usr/bin/env" "${lib.getExe' coreutils "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"}' + ''; postBuild = '' stage3/bin/zig run ../tools/docgen.zig -- ../doc/langref.html.in langref.html --zig $PWD/stage3/bin/zig From b16f240cfd7637efc78028872a84786ee233fadf Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Fri, 24 Jan 2025 15:38:29 +0100 Subject: [PATCH 3/4] zig_0_13: fix darwin SDK lookup --- .../compilers/zig/0.13/default.nix | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkgs/development/compilers/zig/0.13/default.nix b/pkgs/development/compilers/zig/0.13/default.nix index 8ec68f20260f3..0de0f92ebd273 100644 --- a/pkgs/development/compilers/zig/0.13/default.nix +++ b/pkgs/development/compilers/zig/0.13/default.nix @@ -9,6 +9,7 @@ stdenv, testers, zlib, + xcbuild, }: stdenv.mkDerivation (finalAttrs: { @@ -70,12 +71,22 @@ stdenv.mkDerivation (finalAttrs: { # https://github.com/NixOS/nixpkgs/issues/317055#issuecomment-2148438395 strictDeps = !stdenv.cc.isClang; - # 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 = '' - substituteInPlace lib/std/zig/system.zig \ - --replace "/usr/bin/env" "${lib.getExe' coreutils "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. + '' + substituteInPlace lib/std/zig/system.zig \ + --replace "/usr/bin/env" "${lib.getExe' coreutils "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"}' + ''; postBuild = '' stage3/bin/zig build langref From d3a64dc989c22ada53ff380a530b1c95e205dc2a Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Fri, 24 Jan 2025 16:58:26 +0100 Subject: [PATCH 4/4] 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 = ''