Describe the bug
I'm trying to use bazel_6 from nixpkgs on my laptop and use remote builders (buildbarn).
This fails due to patches that are applied in nixpkgs.
Vanilla Bazel has a hardcoded fallback path for bash (/bin/bash) 12. This path is used to invoke shell actions (ctx.actions.run_shell). On NixOS, this obviously doesn't work (/bin/bash doesn't exist). This is why Bazel from nixpkgs replaces this hardcoded path with a bash from nixpkgs.
This has the downside of not producing a working fallback for $PATH (bash from nixpkgs will default initialize $PATH as /no-such-path). The workaround for this is to default initialize the path variables somewhere else. Currently, this is done here.
This works fine for local execution, since this is where this function is called. However, this function is never called for remote execution (it is a hack to override things for the local execution environment only). So when using Bazel from nixpkgs locally and enabling remote execution, the shell is set to a bash from nixpkgs during the analysis phase but the $PATH variable is explicitly left unset by many actions, leading to the PATH in bash being /no-such-path and resulting in no such file or directory errors when executing tools in a script.
I think there are two possible solutions:
- when using remote execution, do not replace the hardcoded
/bin/bash (this is probably not a great fix since it only works for FHS executors)
- instead of replacing
/bin/bash with a regular bash from nixpkgs, add a little helper script that adds shell utils to $PATH. This way, any shell rule created by bazel has a minimal set of tools.
- use
--shell_executable=/bin/bash when turning on remote execution. This has the downside of only working when the remote builder has a shell in that path.
Steps To Reproduce
See this for a detailed reproducer: tweag/rules_nixpkgs#439
Expected behavior
Using bazel from nixpkgs should work with remote execution.
Additional context
Using this version of bazel with remote execution is becoming more viable due to https://github.com/tweag/rules_nixpkgs.
Notify maintainers
@mboes
@marsam
@uri-canva
@cbley
@olebedev
@groodt
@aherrmann
@ylecornec
Metadata
- system: `"x86_64-linux"`
- host os: `Linux 6.5.9, NixOS, 23.05 (Stoat), 23.05.20231027.1a3c95e`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.13.6`
- nixpkgs: `/nix/store/lqfbzmwwanrvbvgsvxa5jbmjbhm5aygr-source`
Describe the bug
I'm trying to use
bazel_6from nixpkgs on my laptop and use remote builders (buildbarn).This fails due to patches that are applied in nixpkgs.
Vanilla Bazel has a hardcoded fallback path for bash (
/bin/bash) 12. This path is used to invoke shell actions (ctx.actions.run_shell). On NixOS, this obviously doesn't work (/bin/bashdoesn't exist). This is why Bazel from nixpkgs replaces this hardcoded path with a bash from nixpkgs.This has the downside of not producing a working fallback for
$PATH(bash from nixpkgs will default initialize$PATHas/no-such-path). The workaround for this is to default initialize the path variables somewhere else. Currently, this is done here.This works fine for local execution, since this is where this function is called. However, this function is never called for remote execution (it is a hack to override things for the local execution environment only). So when using Bazel from nixpkgs locally and enabling remote execution, the shell is set to a bash from nixpkgs during the analysis phase but the
$PATHvariable is explicitly left unset by many actions, leading to the PATH in bash being/no-such-pathand resulting inno such file or directoryerrors when executing tools in a script.I think there are two possible solutions:
/bin/bash(this is probably not a great fix since it only works for FHS executors)/bin/bashwith a regular bash from nixpkgs, add a little helper script that adds shell utils to$PATH. This way, any shell rule created by bazel has a minimal set of tools.--shell_executable=/bin/bashwhen turning on remote execution. This has the downside of only working when the remote builder has a shell in that path.Steps To Reproduce
See this for a detailed reproducer: tweag/rules_nixpkgs#439
Expected behavior
Using bazel from nixpkgs should work with remote execution.
Additional context
Using this version of bazel with remote execution is becoming more viable due to https://github.com/tweag/rules_nixpkgs.
Notify maintainers
@mboes
@marsam
@uri-canva
@cbley
@olebedev
@groodt
@aherrmann
@ylecornec
Metadata
Footnotes
https://github.com/bazelbuild/bazel/blob/37d95846d3258da81c690d4693f1604f5d28087d/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java#L168 ↩
https://github.com/bazelbuild/bazel/blob/37d95846d3258da81c690d4693f1604f5d28087d/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java#L219-L223 ↩