From 4fe8b81bf647cb8254e575b6e7129e597efa5c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Wed, 1 Mar 2023 17:27:43 +0100 Subject: [PATCH] ios: fix xcode using system Node.js version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As discovered in: https://github.com/status-im/status-mobile/pull/15225 The attempt to fix this in: https://github.com/status-im/status-mobile/pull/15180 But it doesn't appear to work, so instead I'm allowing an override of `NODE_BINARY` variable and spetting it when defining the Nix shell. The key things here are: * Xcode injects its own paths into `PATH` which breaks Nix env. * Combining Nix shells with `inputsFrom` does not inherit all vars. It's important to set these variables in `shellHook` and not elsewhere. Signed-off-by: Jakub SokoĊ‚owski --- ios/StatusIm.xcodeproj/project.pbxproj | 4 ++-- nix/mobile/ios/default.nix | 1 + nix/mobile/ios/shells/nodejs.nix | 13 ++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ios/StatusIm.xcodeproj/project.pbxproj b/ios/StatusIm.xcodeproj/project.pbxproj index 3e26645132..3bcc68bda0 100644 --- a/ios/StatusIm.xcodeproj/project.pbxproj +++ b/ios/StatusIm.xcodeproj/project.pbxproj @@ -526,7 +526,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = "/usr/bin/env sh"; - shellScript = "set -o errexit\nexport NODE_BINARY=\"node\"\nexport NODE_ARGS=\" --openssl-legacy-provider --max-old-space-size=16384 \"\n\nbash -x ../node_modules/react-native/scripts/react-native-xcode.sh > ./react-native-xcode.log 2>&1"; + shellScript = "set -o errexit\nexport NODE_BINARY=\"${NODE_BINARY:-node}\"\nexport NODE_ARGS=\" --openssl-legacy-provider --max-old-space-size=16384 \"\n\nbash -x ../node_modules/react-native/scripts/react-native-xcode.sh > ./react-native-xcode.log 2>&1"; }; 0F876BD5356F61BF142A01A0 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; @@ -584,7 +584,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = "/usr/bin/env sh"; - shellScript = "set -o errexit\nexport NODE_BINARY=\"node\"\nexport NODE_ARGS=\" --openssl-legacy-provider --max-old-space-size=16384 \"\n\nbash -x ../node_modules/react-native/scripts/react-native-xcode.sh > ./react-native-xcode.log 2>&1"; + shellScript = "set -o errexit\nexport NODE_BINARY=\"${NODE_BINARY:-node}\"\nexport NODE_ARGS=\" --openssl-legacy-provider --max-old-space-size=16384 \"\n\nbash -x ../node_modules/react-native/scripts/react-native-xcode.sh > ./react-native-xcode.log 2>&1"; }; 3AAD2AD724A3A60E0075D594 /* Run Script */ = { isa = PBXShellScriptBuildPhase; diff --git a/nix/mobile/ios/default.nix b/nix/mobile/ios/default.nix index 835647d41f..4022f2014a 100644 --- a/nix/mobile/ios/default.nix +++ b/nix/mobile/ios/default.nix @@ -20,6 +20,7 @@ in { ]; # WARNING: Executes shellHook in reverse order. + # WARNING: Only some variables are merged. inputsFrom = [ fastlane.shell cocoapods-sh diff --git a/nix/mobile/ios/shells/nodejs.nix b/nix/mobile/ios/shells/nodejs.nix index 49159a437e..762cdff49d 100644 --- a/nix/mobile/ios/shells/nodejs.nix +++ b/nix/mobile/ios/shells/nodejs.nix @@ -1,11 +1,14 @@ -{ mkShell, deps }: +{ mkShell, nodejs, deps }: mkShell { - # Fix for ERR_OSSL_EVP_UNSUPPORTED error. - NODE_OPTIONS = "--openssl-legacy-provider"; - - # check if node modules changed and if so install them + # Check if node modules changed and if so install them. shellHook = '' + # Fix for ERR_OSSL_EVP_UNSUPPORTED error. + export NODE_OPTIONS="--openssl-legacy-provider"; + + # Fix Xcode using system Node.js version. + export NODE_BINARY="${nodejs}/bin/node"; + export STATUS_MOBILE_HOME=$(git rev-parse --show-toplevel) "$STATUS_MOBILE_HOME/nix/scripts/node_modules.sh" ${deps.nodejs-patched} '';