Merge pull request #266847 from malt3/fix/bazel/bashWithUtils

bazel: use bash with fallback $PATH consisting of basic shell utils

authored by Martin Weinelt and committed by GitHub e94bccef d9b120b3

+18 -6
+18 -6
pkgs/development/tools/build-managers/bazel/bazel_6/default.nix
··· 22 22 , file 23 23 , substituteAll 24 24 , writeTextFile 25 + , writeShellApplication 25 26 }: 26 27 27 28 let ··· 127 128 ]; 128 129 129 130 defaultShellPath = lib.makeBinPath defaultShellUtils; 131 + 132 + bashWithDefaultShellUtils = writeShellApplication { 133 + name = "bash"; 134 + runtimeInputs = defaultShellUtils; 135 + text = '' 136 + if [[ "$PATH" == "/no-such-path" ]]; then 137 + export PATH=${defaultShellPath} 138 + fi 139 + exec ${bash}/bin/bash "$@" 140 + ''; 141 + }; 130 142 131 143 platforms = lib.platforms.linux ++ lib.platforms.darwin; 132 144 ··· 420 432 # If you add more replacements here, you must change the grep above! 421 433 # Only files containing /bin are taken into account. 422 434 substituteInPlace "$path" \ 423 - --replace /bin/bash ${bash}/bin/bash \ 424 - --replace "/usr/bin/env bash" ${bash}/bin/bash \ 435 + --replace /bin/bash ${bashWithDefaultShellUtils}/bin/bash \ 436 + --replace "/usr/bin/env bash" ${bashWithDefaultShellUtils}/bin/bash \ 425 437 --replace "/usr/bin/env python" ${python3}/bin/python \ 426 438 --replace /usr/bin/env ${coreutils}/bin/env \ 427 439 --replace /bin/true ${coreutils}/bin/true ··· 436 448 437 449 # bazel test runner include references to /bin/bash 438 450 substituteInPlace tools/build_rules/test_rules.bzl \ 439 - --replace /bin/bash ${bash}/bin/bash 451 + --replace /bin/bash ${bashWithDefaultShellUtils}/bin/bash 440 452 441 453 for i in $(find tools/cpp/ -type f) 442 454 do 443 455 substituteInPlace $i \ 444 - --replace /bin/bash ${bash}/bin/bash 456 + --replace /bin/bash ${bashWithDefaultShellUtils}/bin/bash 445 457 done 446 458 447 459 # Fixup scripts that generate scripts. Not fixed up by patchShebangs below. 448 460 substituteInPlace scripts/bootstrap/compile.sh \ 449 - --replace /bin/bash ${bash}/bin/bash 461 + --replace /bin/bash ${bashWithDefaultShellUtils}/bin/bash 450 462 451 463 # add nix environment vars to .bazelrc 452 464 cat >> .bazelrc <<EOF ··· 523 535 in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches 524 536 + genericPatches; 525 537 526 - buildInputs = [buildJdk] ++ defaultShellUtils; 538 + buildInputs = [buildJdk bashWithDefaultShellUtils] ++ defaultShellUtils; 527 539 528 540 # when a command can’t be found in a bazel build, you might also 529 541 # need to add it to `defaultShellPath`.