| Tim Windelschmidt | 5d357d8 | 2025-07-10 18:47:15 +0200 | [diff] [blame^] | 1 | { lib |
| 2 | , makeBinaryWrapper |
| 3 | , writeShellApplication |
| 4 | , bash |
| 5 | , stdenv |
| 6 | , |
| 7 | }: |
| 8 | { defaultShellUtils }: |
| 9 | let |
| 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 | |
| 28 | in |
| 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 | } |