From 90cf03cc56b00c7da257f3cfdc88976cadc0f056 Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Thu, 6 Feb 2025 14:56:35 +0100 Subject: [PATCH] zig: refactor system env substitution --- pkgs/development/compilers/zig/generic.nix | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pkgs/development/compilers/zig/generic.nix b/pkgs/development/compilers/zig/generic.nix index 159ca35a813a..65959289cb6c 100644 --- a/pkgs/development/compilers/zig/generic.nix +++ b/pkgs/development/compilers/zig/generic.nix @@ -87,18 +87,17 @@ stdenv.mkDerivation (finalAttrs: { # 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 finalAttrs.version "0.12" then - '' - substituteInPlace lib/std/zig/system.zig \ - --replace-fail "/usr/bin/env" "${coreutils}/bin/env" - '' - else - '' - substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \ - --replace-fail "/usr/bin/env" "${coreutils}/bin/env" - '' - ) + let + zigSystemPath = + if lib.versionAtLeast finalAttrs.version "0.12" then + "lib/std/zig/system.zig" + else + "lib/std/zig/system/NativeTargetInfo.zig"; + in + '' + substituteInPlace ${zigSystemPath} \ + --replace-fail "/usr/bin/env" "${lib.getExe' coreutils "env"}" + '' # Zig tries to access xcrun and xcode-select at the absolute system path to query the macOS SDK # location, which does not work in the darwin sandbox. # Upstream issue: https://github.com/ziglang/zig/issues/22600