From 4844b997d434affa8b6caf9b1b59b7850c276b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Roche?= Date: Tue, 23 Jan 2024 11:05:12 +0100 Subject: [PATCH] nix: fix installCheckPhase crashes on Darwin While building nix on Darwin, I encountered an error in the `installCheckPhase`: ``` nix> building '/private/tmp/nix-build-nix-2.17.1.drv-1/nix-test/tests/fetchurl/store/mkc9z3arar02wi5jii655cjhdinx4npy-fetchurl.sh.drv'... nix> waiting for children nix> building of '/private/tmp/nix-build-nix-2.17.1.drv-1/nix-test/tests/fetchurl/store/mkc9z3arar02wi5jii655cjhdinx4npy-fetchurl.sh.drv^out' from .drv file: read 377 bytes nix> objc[70707]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. nix> objc[70707]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug. nix> waiting for children ``` I noticed that #278802 should have addressed this problem, but it didn't. The solution for me was to replace `yes` with `YES`. As it turns out, most of the references to `OBJC_DISABLE_INITIALIZE_FORK_SAFETY` use `YES` instead of `yes`. https://airflow.apache.org/blog/airflow-1.10.10/#running-airflow-on-macos http://sealiesoftware.com/blog/archive/2017/6/5/Objective-C_and_fork_in_macOS_1013.html The objective C code that parses the environment variable is defined in the function `environ_init` in [here](https://github.com/opensource-apple/objc4/blob/cd5e62a5597ea7a31dccef089317abb3a661c154/runtime/objc-runtime.mm#L265) and it does `*opt->var = (0 == strcmp(value, "YES"));`. ``` % nix-info -m - system: `"aarch64-darwin"` - host os: `Darwin 21.3.0, macOS 12.2.1` - multi-user?: `yes` - sandbox: `yes` - version: `nix-env (Nix) 2.19.2` - channels(hetzner): `"darwin, nixpkgs-22.05-darwin"` - channels(root): `"darwin, nixpkgs-23.05-darwin"` - nixpkgs: `/Users/hetzner/git/nixpkgs` ``` --- pkgs/tools/package-management/nix/common.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/package-management/nix/common.nix b/pkgs/tools/package-management/nix/common.nix index 946407826f25..670e2282aa20 100644 --- a/pkgs/tools/package-management/nix/common.nix +++ b/pkgs/tools/package-management/nix/common.nix @@ -216,7 +216,7 @@ self = stdenv.mkDerivation { # Prevent crashes in libcurl due to invoking Objective-C `+initialize` methods after `fork`. # See http://sealiesoftware.com/blog/archive/2017/6/5/Objective-C_and_fork_in_macOS_1013.html. + lib.optionalString stdenv.isDarwin '' - export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=yes + export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES '' # See https://github.com/NixOS/nix/issues/5687 + lib.optionalString (atLeast25 && stdenv.isDarwin) ''