Describe the bug
The environment, $PATH specifically, differs between build actions that use ctx.action.run and those that use ctx.action.run_shell when Bazel is provided by nixpkgs. Using run_shell $PATH will point to tools in the Nix store, using run instead will point to tools on the host system. This is particularly an issue for MacOS users where coreutils provided by Nix are GNU coreutils, while system coreutils are BSD flavored. E.g. readlink -f works with Nix coreutils, but fails with stock MacOS coreutils.
To Reproduce
Steps to reproduce the behavior:
- Checkout aherrmann/nixpkgs-bazel-run-env@077e2bd
- Build targets calling a shell script using
ctx.actions.run and ctx.actions.run_shell respectively.
$ nix-shell --pure --run 'bazel build //:all'
- Observe the difference in outcome.
$ cat bazel-bin/using-run.txt
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
readlink is /usr/bin/readlink
$ cat bazel-bin/using-run-shell.txt
/nix/store/58in3hsawf6g1adx99sphi460nzmaqxq-bash-4.4-p23/bin:/nix/store/vssdbs9s059qm5rqpw5q25z3c2d065f7-coreutils-8.31/bin:/nix/store/i13xf7dasqs66ylbnkbprg742a5izh8r-findutils-4.7.0/bin:/nix/store/nw699blhmjls6j1xbb938a1rjq6bw3jf-gawk-5.1.0/bin:/nix/store/dh5d3cpxwk5aixgphx0b61rxq9bfdmlr-gnugrep-3.4/bin:/nix/store/4mwsggbn3gijwixc09jwzh8l42h15n4m-gnutar-1.32/bin:/nix/store/zx7fxdqymhhgrqv6gfynsqzp7dmgn2hs-gnused-4.8/bin:/nix/store/bryws27lqm1j7vlssrd9xzqk9pf5rvlz-gzip-1.10/bin:/nix/store/vb47vacr597kabig0gvaqq2lk2wjfxnw-which-2.21/bin:/nix/store/jvbw3n6v3mp4yx33h7fa2x1zdak40g2a-unzip-6.0/bin:/nix/store/b081hh3zm012vqnwr3srgkvsbzmngkzf-file-5.39/bin:/nix/store/4ipxmrbv36fnaw6i5nfv2ccqdb4c94c2-zip-3.0/bin
readlink is /nix/store/vssdbs9s059qm5rqpw5q25z3c2d065f7-coreutils-8.31/bin/readlink
Expected behavior
I would expect the environment to be consistent between both flavors of actions ctx.actions.run and ctx.actions.run_shell. I would expect $PATH to point to tools in the Nix store in both cases.
Notify maintainers
@Profpatsch @mboes
Metadata
Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.
- system: `"x86_64-linux"`
- host os: `Linux 5.3.0-64-generic, Ubuntu, 19.10 (Eoan Ermine)`
- multi-user?: `no`
- sandbox: `yes`
- version: `nix-env (Nix) 2.3.2`
- channels(aj): `"nixpkgs-20.09pre214374.1fe82110feb"`
- nixpkgs: `/home/aj/.nix-defexpr/channels/nixpkgs`
Maintainer information:
# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
Describe the bug
The environment,
$PATHspecifically, differs between build actions that usectx.action.runand those that usectx.action.run_shellwhen Bazel is provided by nixpkgs. Usingrun_shell$PATHwill point to tools in the Nix store, usingruninstead will point to tools on the host system. This is particularly an issue for MacOS users where coreutils provided by Nix are GNU coreutils, while system coreutils are BSD flavored. E.g.readlink -fworks with Nix coreutils, but fails with stock MacOS coreutils.To Reproduce
Steps to reproduce the behavior:
ctx.actions.runandctx.actions.run_shellrespectively.Expected behavior
I would expect the environment to be consistent between both flavors of actions
ctx.actions.runandctx.actions.run_shell. I would expect$PATHto point to tools in the Nix store in both cases.Notify maintainers
@Profpatsch @mboes
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"and paste the result.Maintainer information: