From 403a0d57aa2959f0dbd2473bc99f57e0cf06c50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Mon, 6 May 2024 18:16:50 +0200 Subject: [PATCH] Always initialize curl in parent process on darwin Because of an objc quirk[1], calling curl_global_init for the first time after fork() will always result in a crash. Up until now the solution has been to set OBJC_DISABLE_INITIALIZE_FORK_SAFETY for every nix process to ignore that error. This is less than ideal because we were setting it in package.nix, which meant that running nix tests locally would fail because that variable was not set. Instead of working around that error we address it at the core - by calling curl_global_init inside initLibStore, which should mean curl will already have been initialized by the time we try to do so in a forked process. [1] https://github.com/appleopen/objc4/blob/da82a83b15613fd13b296d9d4f0d68a261852ff3/runtime/objc-initialize.mm#L417-L439 --- misc/launchd/org.nixos.nix-daemon.plist.in | 5 ----- package.nix | 4 ---- src/libstore/globals.cc | 2 ++ 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/misc/launchd/org.nixos.nix-daemon.plist.in b/misc/launchd/org.nixos.nix-daemon.plist.in index e1470cf99..664608305 100644 --- a/misc/launchd/org.nixos.nix-daemon.plist.in +++ b/misc/launchd/org.nixos.nix-daemon.plist.in @@ -2,11 +2,6 @@ - EnvironmentVariables - - OBJC_DISABLE_INITIALIZE_FORK_SAFETY - YES - Label org.nixos.nix-daemon KeepAlive diff --git a/package.nix b/package.nix index 455e21135..af0a44fee 100644 --- a/package.nix +++ b/package.nix @@ -400,10 +400,6 @@ stdenv.mkDerivation (finalAttrs: { mesonInstallCheckFlags = [ "--suite=installcheck" ]; - preInstallCheck = lib.optionalString stdenv.hostPlatform.isDarwin '' - export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES - ''; - installCheckPhase = lib.optionalString buildWithMeson '' runHook preInstallCheck flagsArray=($mesonInstallCheckFlags "''${mesonInstallCheckFlagsArray[@]}") diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index b7397da1a..1233973e3 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -25,6 +25,7 @@ #include "config-impl.hh" #ifdef __APPLE__ +#include #include #endif @@ -413,6 +414,7 @@ void initLibStore() { sshd). This breaks build users because they don't have access to the TMPDIR, in particular in ‘nix-store --serve’. */ #if __APPLE__ + curl_global_init(CURL_GLOBAL_ALL); if (getEnv("TMPDIR").value_or("/tmp").starts_with("/var/folders/")) unsetenv("TMPDIR"); #endif