blob: 0deb516d760d0c409c7944b509ae67365ad08629 [file] [log] [blame]
Tim Windelschmidt5d357d82025-07-10 18:47:15 +02001{ lib
2, makeBinaryWrapper
3, writeShellApplication
4, bash
5, stdenv
6,
7}:
8{ defaultShellUtils }:
9let
10 defaultShellPath = lib.makeBinPath defaultShellUtils;
11
12 bashWithDefaultShellUtilsSh = writeShellApplication {
13 name = "bash";
14 runtimeInputs = defaultShellUtils;
15 # Empty PATH in Nixpkgs Bash is translated to /no-such-path
16 # On other distros empty PATH search fallback is looking in standard
17 # locations like /bin,/usr/bin
18 # For Bazel many rules rely on such search finding some common utils,
19 # so we provide them in case rules or arguments didn't specify a precise PATH
20 text = ''
21 if [[ "$PATH" == "/no-such-path" ]]; then
22 export PATH=${defaultShellPath}
23 fi
24 exec ${bash}/bin/bash "$@"
25 '';
26 };
27
28in
29{
30 inherit defaultShellUtils defaultShellPath;
31 # Script-based interpreters in shebangs aren't guaranteed to work,
32 # especially on MacOS. So let's produce a binary
33 bashWithDefaultShellUtils = stdenv.mkDerivation {
34 name = "bash";
35 src = bashWithDefaultShellUtilsSh;
36 nativeBuildInputs = [ makeBinaryWrapper ];
37 buildPhase = ''
38 makeWrapper ${bashWithDefaultShellUtilsSh}/bin/bash $out/bin/bash
39 '';
40 };
41}