Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions pkgs/development/tools/build-managers/bazel/bazel_6/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
, file
, substituteAll
, writeTextFile
, writeShellApplication
}:

let
Expand Down Expand Up @@ -128,6 +129,17 @@ let

defaultShellPath = lib.makeBinPath defaultShellUtils;

bashWithDefaultShellUtils = writeShellApplication {
name = "bash";
runtimeInputs = defaultShellUtils;
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";
Expand Down Expand Up @@ -420,8 +432,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
Expand All @@ -436,17 +448,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
Expand Down Expand Up @@ -523,7 +535,7 @@ stdenv.mkDerivation rec {
in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches
+ genericPatches;

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`.
Expand Down