From cae03b78b484b952422854834b7de02cb29c1e3f Mon Sep 17 00:00:00 2001 From: Alex James Date: Sun, 16 Jun 2024 17:35:52 -0500 Subject: [PATCH] zig: fix build on Darwin with sandbox enabled During stage 3 of compilation, Zig calls `std.zig.system.darwin.macos.detect`, which parses /System/Library/CoreServices/.SystemVersionPlatform.plist and /System/Library/CoreServices/SystemVersion.plist[^1] to determine the OS version. These paths are inaccessible when the sandbox is enabled, which causes the build to fail with `OSVersionDetectionFail`[^2]. Fix the build with the relaxed sandbox option by adding these paths to `__impureHostDeps`. [^1]: https://github.com/ziglang/zig/blob/cd62005f19ff966d2c42de4daeb9a1e4b644bf76/lib/std/zig/system/darwin/macos.zig [^2]: https://github.com/NixOS/nixpkgs/issues/287861#issuecomment-2148703491 --- pkgs/development/compilers/zig/0.12/default.nix | 10 ++++++++++ pkgs/development/compilers/zig/0.13/default.nix | 10 ++++++++++ pkgs/development/compilers/zig/generic.nix | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/pkgs/development/compilers/zig/0.12/default.nix b/pkgs/development/compilers/zig/0.12/default.nix index 092b416c7903..88bb0169dd8a 100644 --- a/pkgs/development/compilers/zig/0.12/default.nix +++ b/pkgs/development/compilers/zig/0.12/default.nix @@ -38,6 +38,16 @@ stdenv.mkDerivation (finalAttrs: { llvm ]); + # On Darwin, Zig calls std.zig.system.darwin.macos.detect during the build, + # which parses /System/Library/CoreServices/SystemVersion.plist and + # /System/Library/CoreServices/.SystemVersionPlatform.plist to determine the + # OS version. This causes the build to fail during stage 3 with + # OSVersionDetectionFail when the sandbox is enabled. + __impureHostDeps = lib.optionals stdenv.isDarwin [ + "/System/Library/CoreServices/.SystemVersionPlatform.plist" + "/System/Library/CoreServices/SystemVersion.plist" + ]; + outputs = [ "out" "doc" diff --git a/pkgs/development/compilers/zig/0.13/default.nix b/pkgs/development/compilers/zig/0.13/default.nix index bdc01ba47f9f..0c72b459facf 100644 --- a/pkgs/development/compilers/zig/0.13/default.nix +++ b/pkgs/development/compilers/zig/0.13/default.nix @@ -38,6 +38,16 @@ stdenv.mkDerivation (finalAttrs: { llvm ]); + # On Darwin, Zig calls std.zig.system.darwin.macos.detect during the build, + # which parses /System/Library/CoreServices/SystemVersion.plist and + # /System/Library/CoreServices/.SystemVersionPlatform.plist to determine the + # OS version. This causes the build to fail during stage 3 with + # OSVersionDetectionFail when the sandbox is enabled. + __impureHostDeps = lib.optionals stdenv.isDarwin [ + "/System/Library/CoreServices/.SystemVersionPlatform.plist" + "/System/Library/CoreServices/SystemVersion.plist" + ]; + outputs = [ "out" "doc" diff --git a/pkgs/development/compilers/zig/generic.nix b/pkgs/development/compilers/zig/generic.nix index f3c725e1e5ce..3369f5d40c2c 100644 --- a/pkgs/development/compilers/zig/generic.nix +++ b/pkgs/development/compilers/zig/generic.nix @@ -36,6 +36,16 @@ stdenv.mkDerivation (finalAttrs: { llvm ]); + # On Darwin, Zig calls std.zig.system.darwin.macos.detect during the build, + # which parses /System/Library/CoreServices/SystemVersion.plist and + # /System/Library/CoreServices/.SystemVersionPlatform.plist to determine the + # OS version. This causes the build to fail during stage 3 with + # OSVersionDetectionFail when the sandbox is enabled. + __impureHostDeps = lib.optionals stdenv.isDarwin [ + "/System/Library/CoreServices/.SystemVersionPlatform.plist" + "/System/Library/CoreServices/SystemVersion.plist" + ]; + env.ZIG_GLOBAL_CACHE_DIR = "$TMPDIR/zig-cache"; # Zig's build looks at /usr/bin/env to find dynamic linking info. This doesn't