summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Maudoux <guillaume.maudoux@tweag.io>2023-12-18 17:32:07 +0100
committergithub-actions[bot] <github-actions[bot]@users.noreply.github.com>2024-01-02 08:19:49 +0000
commit801571b76e3b042e5d1f6bde0764312e6e2b89f8 (patch)
treea0064966dd56d65199de0d362ab883c8ce1447af
parentbazel_7: fix protobuf test on darwin (diff)
downloadnixpkgs-801571b76e3b042e5d1f6bde0764312e6e2b89f8.tar.gz
bazel_7: backport bazel_6 bash fixes for remote execution
(cherry picked from commit f35225d3d648e1d0b3e5d36e035d542934826e64)
-rw-r--r--pkgs/development/tools/build-managers/bazel/bazel_7/default.nix52
1 files changed, 31 insertions, 21 deletions
diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/default.nix
index 0cc2937c3640..34e371a43423 100644
--- a/pkgs/development/tools/build-managers/bazel/bazel_7/default.nix
+++ b/pkgs/development/tools/build-managers/bazel/bazel_7/default.nix
@@ -3,26 +3,18 @@
, callPackage
, lib
, fetchurl
-, fetchpatch
-, fetchFromGitHub
-, runCommand
-, runCommandCC
, makeWrapper
-, recurseIntoAttrs
-, newScope
, writeTextFile
-, autoPatchelfHook
, substituteAll
+, writeShellApplication
+, makeBinaryWrapper
# this package (through the fixpoint glass)
, bazel_self
# native build inputs
, runtimeShell
-, lr
-, xe
, zip
, unzip
, bash
-, writeCBin
, coreutils
, which
, gawk
@@ -36,9 +28,7 @@
, file
, installShellFiles
, lndir
- # updater
, python3
-, writeScript
# Apple dependencies
, cctools
, libcxx
@@ -50,12 +40,10 @@
# Allow to independently override the jdks used to build and run respectively
, buildJdk
, runJdk
- # Downstream packages for tests
-, bazel-watcher
# Always assume all markers valid (this is needed because we remove markers; they are non-deterministic).
# Also, don't clean up environment variables (so that NIX_ environment variables are passed to compilers).
, enableNixHacks ? false
-}@args:
+}:
let
version = "7.0.0";
@@ -131,6 +119,28 @@ let
defaultShellPath = lib.makeBinPath defaultShellUtils;
+ bashWithDefaultShellUtilsSh = writeShellApplication {
+ name = "bash";
+ runtimeInputs = defaultShellUtils;
+ text = ''
+ if [[ "$PATH" == "/no-such-path" ]]; then
+ export PATH=${defaultShellPath}
+ fi
+ exec ${bash}/bin/bash "$@"
+ '';
+ };
+
+ # Script-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;
inherit (stdenv.hostPlatform) isDarwin isAarch64;
@@ -319,10 +329,10 @@ stdenv.mkDerivation rec {
# If you add more replacements here, you must change the grep above!
# Only files containing /bin are taken into account.
sedVerbose "$path" \
- -e 's!/usr/local/bin/bash!${bash}/bin/bash!g' \
- -e 's!/usr/bin/bash!${bash}/bin/bash!g' \
- -e 's!/bin/bash!${bash}/bin/bash!g' \
- -e 's!/usr/bin/env bash!${bash}/bin/bash!g' \
+ -e 's!/usr/local/bin/bash!${bashWithDefaultShellUtils}/bin/bash!g' \
+ -e 's!/usr/bin/bash!${bashWithDefaultShellUtils}/bin/bash!g' \
+ -e 's!/bin/bash!${bashWithDefaultShellUtils}/bin/bash!g' \
+ -e 's!/usr/bin/env bash!${bashWithDefaultShellUtils}/bin/bash!g' \
-e 's!/usr/bin/env python2!${python3}/bin/python!g' \
-e 's!/usr/bin/env python!${python3}/bin/python!g' \
-e 's!/usr/bin/env!${coreutils}/bin/env!g' \
@@ -331,7 +341,7 @@ stdenv.mkDerivation rec {
# Fixup scripts that generate scripts. Not fixed up by patchShebangs below.
sedVerbose scripts/bootstrap/compile.sh \
- -e 's!/bin/bash!${bash}/bin/bash!g' \
+ -e 's!/bin/bash!${bashWithDefaultShellUtils}/bin/bash!g' \
-e 's!shasum -a 256!sha256sum!g'
# Augment bundled repository_cache with our extra paths
@@ -402,7 +412,7 @@ stdenv.mkDerivation rec {
# Bazel starts a local server and needs to bind a local address.
__darwinAllowLocalNetworking = true;
- buildInputs = [ buildJdk ] ++ defaultShellUtils;
+ buildInputs = [ buildJdk bashWithDefaultShellUtils ] ++ defaultShellUtils;
# when a command can’t be found in a bazel build, you might also
# need to add it to `defaultShellPath`.