From 7377bba1c77b8d4f2f6b9957df34f354bf1da601 Mon Sep 17 00:00:00 2001 From: Dmitry Ivankov Date: Mon, 20 Nov 2023 01:49:45 +0100 Subject: [PATCH 1/2] bazel_6: fix: make patched bash a native binary https://hydra.nixos.org/build/240805256/nixlog/1 https://hydra.nixos.org/build/240805170/nixlog/2 Failure is a bit obscured but long story short, a script within bazel gets custom nixpkgs shebang which in turn makes shell run in POSIX-compatible mode. Bazel expects bash in non-POSIX mode and osx-specific script starts to fail due to `set -e` and subshell interaction differences in those modes (sub-shells and functions suddently start inheriting `set -e` and fail to produce desired output). More debug info is available in #267670 Shell scripts aren't guaranteed to work as interpreters in shebang. In particular thin shell wrappers aren't shebang-ready on MacOS. It may work sometimes depending on what exactly would try to execute a script with such shebang, but generally it's not guaranteed to work. See #124556 Bash wrapper was introduced in #266847 and so far seems like the issue only affects darwin builds: hydra failure is in osx-specific script, also shebang issue is usually darwin-specific. Let's wrap it as a native binary to make it shebang-compatible. The wrapper is only currently added to `bazel_6` so no need for changes in other versions. ZHF: #265948 --- .../tools/build-managers/bazel/bazel_6/default.nix | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkgs/development/tools/build-managers/bazel/bazel_6/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_6/default.nix index 35f1c9980b4d..9aee8c394f5c 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_6/default.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_6/default.nix @@ -23,6 +23,7 @@ , substituteAll , writeTextFile , writeShellApplication +, makeBinaryWrapper }: let @@ -129,7 +130,7 @@ let defaultShellPath = lib.makeBinPath defaultShellUtils; - bashWithDefaultShellUtils = writeShellApplication { + bashWithDefaultShellUtilsSh = writeShellApplication { name = "bash"; runtimeInputs = defaultShellUtils; text = '' @@ -140,6 +141,17 @@ let ''; }; + # Sript-based interpreters in shebangs aren't guaranteed to work, + # especially on MacOS. So let's produce a binary + bashWithDefaultShellUtils = stdenv.mkDerivation { + name = "bash"; + src = bashWithDefaultShellUtilsSh; + nativeBuildInputs = [ makeBinaryWrapper ]; + buildPhase = '' + makeWrapper ${bashWithDefaultShellUtilsSh}/bin/bash $out/bin/bash + ''; + }; + platforms = lib.platforms.linux ++ lib.platforms.darwin; system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux"; From dd854492117036e0c218d63ba3a5b2894cf7ce89 Mon Sep 17 00:00:00 2001 From: Dmitry Ivankov Date: Mon, 20 Nov 2023 02:13:23 +0100 Subject: [PATCH 2/2] Update pkgs/development/tools/build-managers/bazel/bazel_6/default.nix Co-authored-by: Uri Baghin --- pkgs/development/tools/build-managers/bazel/bazel_6/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/tools/build-managers/bazel/bazel_6/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_6/default.nix index 9aee8c394f5c..fb1f4a8f319c 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_6/default.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_6/default.nix @@ -141,7 +141,7 @@ let ''; }; - # Sript-based interpreters in shebangs aren't guaranteed to work, + # Script-based interpreters in shebangs aren't guaranteed to work, # especially on MacOS. So let's produce a binary bashWithDefaultShellUtils = stdenv.mkDerivation { name = "bash";