summary refs log tree commit diff
path: root/pkgs/development/tools/build-managers
diff options
context:
space:
mode:
authorMalte Poll <1780588+malt3@users.noreply.github.com>2023-11-02 13:13:00 +0100
committerBjørn Forsman <bjorn.forsman@gmail.com>2023-11-11 00:25:53 +0100
commit3576806d7edc615b2e89ee4f845d67c5b6c7ecc1 (patch)
treeade4e3c0af0861002112f4328769ecc9dc09b17c /pkgs/development/tools/build-managers
parent061b245b4721853f5552d71dcc1f7c230d9ad0f7 (diff)
downloadnixpkgs-3576806d7edc615b2e89ee4f845d67c5b6c7ecc1.tar
nixpkgs-3576806d7edc615b2e89ee4f845d67c5b6c7ecc1.tar.gz
nixpkgs-3576806d7edc615b2e89ee4f845d67c5b6c7ecc1.tar.bz2
nixpkgs-3576806d7edc615b2e89ee4f845d67c5b6c7ecc1.tar.lz
nixpkgs-3576806d7edc615b2e89ee4f845d67c5b6c7ecc1.tar.xz
nixpkgs-3576806d7edc615b2e89ee4f845d67c5b6c7ecc1.tar.zst
nixpkgs-3576806d7edc615b2e89ee4f845d67c5b6c7ecc1.zip
bazel: use bash with fallback $PATH consisting of basic shell utils
Diffstat (limited to 'pkgs/development/tools/build-managers')
-rw-r--r--pkgs/development/tools/build-managers/bazel/bazel_6/default.nix21
1 files changed, 16 insertions, 5 deletions
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 8fb37a9f666..de82eb54eb9 100644
--- a/pkgs/development/tools/build-managers/bazel/bazel_6/default.nix
+++ b/pkgs/development/tools/build-managers/bazel/bazel_6/default.nix
@@ -22,6 +22,7 @@
 , file
 , substituteAll
 , writeTextFile
+, writeShellApplication
 }:
 
 let
@@ -128,6 +129,16 @@ let
 
   defaultShellPath = lib.makeBinPath defaultShellUtils;
 
+  bashWithDefaultShellUtils = writeShellApplication {
+    name = "bash";
+    text = ''
+      if [[ "$PATH" == "/no-such-path" ]]; then
+        export PATH=${defaultShellPath}
+      fi
+      exec ${bash}/bin/bash "$@"
+    '';
+  };
+
   platforms = lib.platforms.linux ++ lib.platforms.darwin;
 
   system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux";
@@ -420,8 +431,8 @@ stdenv.mkDerivation rec {
         # If you add more replacements here, you must change the grep above!
         # Only files containing /bin are taken into account.
         substituteInPlace "$path" \
-          --replace /bin/bash ${bash}/bin/bash \
-          --replace "/usr/bin/env bash" ${bash}/bin/bash \
+          --replace /bin/bash ${bashWithDefaultShellUtils}/bin/bash \
+          --replace "/usr/bin/env bash" ${bashWithDefaultShellUtils}/bin/bash \
           --replace "/usr/bin/env python" ${python3}/bin/python \
           --replace /usr/bin/env ${coreutils}/bin/env \
           --replace /bin/true ${coreutils}/bin/true
@@ -436,17 +447,17 @@ stdenv.mkDerivation rec {
 
       # bazel test runner include references to /bin/bash
       substituteInPlace tools/build_rules/test_rules.bzl \
-        --replace /bin/bash ${bash}/bin/bash
+        --replace /bin/bash ${bashWithDefaultShellUtils}/bin/bash
 
       for i in $(find tools/cpp/ -type f)
       do
         substituteInPlace $i \
-          --replace /bin/bash ${bash}/bin/bash
+          --replace /bin/bash ${bashWithDefaultShellUtils}/bin/bash
       done
 
       # Fixup scripts that generate scripts. Not fixed up by patchShebangs below.
       substituteInPlace scripts/bootstrap/compile.sh \
-          --replace /bin/bash ${bash}/bin/bash
+          --replace /bin/bash ${bashWithDefaultShellUtils}/bin/bash
 
       # add nix environment vars to .bazelrc
       cat >> .bazelrc <<EOF