-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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: PATH differs between ctx.actions.run and ctx.actions.run_shell #94222
Comments
I marked this as stale due to inactivity. → More info |
On NixOS, this problem is even more important. If we follow the steps to reproduce the bug, the build of the
whereas the build of the What seems to be happeningUsing the bazel
Since the script starts with Since What to do ?In the Should we do something similar in the If so do you have some opinions/pointers about the best way to go about it ? Metadata[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
- host os: `Linux 5.10.57, NixOS, 21.11 (Porcupine)`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.3.15`
- channels(root): `"nixos-21.11pre309670.253aecf69ed"`
- channels(stan): `""`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos` |
Is there any workaround available for this issue? E.g. what about built in rules, like sh_binary? |
In our case, we had an implementation of the following rule: This rule uses https://docs.bazel.build/versions/main/skylark/lib/actions.html#run Once this is True, Nix doesn't experience the reported problem any more. I guess any rule implementations, that use |
We have found in the past that |
I opened the draft PR #146389 which fixed this problem for me, but was not extensively tested. |
Another way to fix the changing |
Agreed, generally I'd recommend setting this flag. AFAIK there are some cases where it can cause issues (bazelbuild/bazel#7026), so it may not be compatible with all use-cases. But, it has worked well in the cases where I used it as well. It's worth pointing out that in this case changes to |
Writing here so that my temporary knowledge is not lost - |
bazel (and its community of rules) is a bit of a mess when it comes to passing around env values, including $PATH, resulting in some actions not receiving the $PATH value set via `--action_path=PATH=...` that we rely on. Bazel 6 in nixpkgs had [the following patch](https://sourcegraph.com/github.com/NixOS/nixpkgs/-/blob/pkgs/development/tools/build-managers/bazel/bazel_6/actions_path.patch) that hardcodes a set of packages to include in that case, which is currently missing from Bazel 7 in nixpkgs, so we (temporarily, hopefully) reintroduce that patch locally. See: NixOS/nixpkgs#262152 (comment) and NixOS/nixpkgs#94222 for some reading I plan to move more bazel stuff out of shell.nix perhaps, into bazel.nix, as its a tad messy all-in-one ## Test plan `bazel build //client/web/dist` is successful
There are 2 things which may be leading to this issue.
These defaults can be avoided with |
Describe the bug
The environment,
$PATH
specifically, differs between build actions that usectx.action.run
and those that usectx.action.run_shell
when Bazel is provided by nixpkgs. Usingrun_shell
$PATH
will point to tools in the Nix store, usingrun
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:
ctx.actions.run
andctx.actions.run_shell
respectively.Expected behavior
I would expect the environment to be consistent between both flavors of actions
ctx.actions.run
andctx.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.Maintainer information:
The text was updated successfully, but these errors were encountered: