Skip to content

bazel_8: Add crucial packages to the standard shell environment - #489519

Merged
samuela merged 1 commit into
NixOS:masterfrom
hzeller:feature-20260211-add-crucial-shell
Mar 12, 2026
Merged

samuela merged 1 commit into
NixOS:masterfrom
hzeller:feature-20260211-add-crucial-shell

Conversation

@hzeller

@hzeller hzeller commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

A lot of parts of bazel and standard packages ssume bash existence; they should be able to call /usr/bin/env bash.

Also, rules_python uses python3 as a bootstrap way to call other scripts (even if it uses its own interpreter).

Both of these are important and have been in the
bazel 7 package
https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/ba/bazel_7/package.nix#L87-L104
... but got lost in the bazel_8 package.

Things that used to compile with bazel 7 now break with bazel 8 on nix.

So: re-adding these crucial packages to the shell environment bazel has available when executing actions.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

@hzeller
hzeller force-pushed the feature-20260211-add-crucial-shell branch from fa5c161 to b75357a Compare February 11, 2026 19:57
@hzeller hzeller changed the title bazel_8: Add crucial packages to the standard shell environment. bazel_8: Add crucial packages to the standard shell environment Feb 11, 2026
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Feb 11, 2026
Comment thread pkgs/by-name/ba/bazel_8/package.nix Outdated
gnused
gnutar
gzip
python3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you provide more details about when exactly this helps? Similar to #464436 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rules_python uses the system python3 to bootstrap calling the python interpreter of py_binary(). So that makes calls to py_binary() outputs fail without a system Python.

Independent of that, like the other coreutils many projects assume python3 as a standard component available on the system. So without this, a lot of projects are excluded, thus putting it in the minimal environment is needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, since we like hermetic systems, we all would like bazel to be more hermetic, but currently it isn't, so this is why we need these dependencies.

I am actively working towards bazel being more hermetic that expects the minimum from the host system (e.g. I will make a way to have the bazel CI also provide a nix platform, and am talking with a bunch of maintainers to get their rules_* more compliant).
So hopefully in the future, we can reduce the minium dependencies.

But as of today, bazel and many rules_* as well as projects are not there yet, and until then, we have to provide the dependencies that are commonly needed. There are more projects using bazel 8 now, but currently as a user, bazel_8 on Nix is not useful due to the removal of bash and python3.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing news! Do you have some link to this initiative that could be added as a comment to this list?

But I still would love to see examples I could reproduce (doesn't have to be exhaustive list of cases that fail, just some that fail, if issue is common shouldn't be hard to collect?).

For rules_python a bit inconclusive, docs still refer to system python needed for bootstrap, but otoh bazel-contrib/rules_python#1929 is merged
For bash also would be good to have an example (additional fun is whether bash in the list should be the hacked bash or upstream(ok, nixpkgs version of) bash)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can try to play with rules_python&rules_shell myself, but original use-case/setup would be even better

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, I am working on a somewhat big project, so I don't have a small use-case.
The following might take a while to compile
https://github.com/The-OpenROAD-Project/OpenROAD
(comment out "@llvm_toolchain//:all" in MODULE.bazel as that is not compatible with nix; just use pkgs.clang19Stdenv)

Here is an example of a target that is a broken: the py_test() and requires both, python3 (to bootstrap that test and bash (bazel_tools/tools/test/generate-xml.sh))

bazel test -c opt //src/gpl/test:simple08

As I said, for now we should focus to support existing projects, and I work in the background to make the bazel and the whole infrastructure better in non-leaky hermeticity (e.g. getting Nix as a CI platform on bazel central registry).

Nothing is helped if we have a 'pure' bazel, but that is not usable in practice - in particular since we all want to encourage people working more towards using hermetic tools.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repro works for me too, and with bazel test --@rules_python//python/config_settings:bootstrap_impl=script ... it fails with

Executing tests from //:some_test
-----------------------------------------------------------------------------
Could not start dynamically linked executable: ...../execroot/_main/bazel-out/k8-fastbuild/bin/some_test.runfiles/_main/_some_test.venv/bin/python3
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld

which is another can of worms of even hermetic rules compatibility with NixOS without FHS wrapper..

Will have a little closer look. Also maybe this default shell could be runtime-parameterized for faster investigation&experimentation in future (and maybe that even could be submitted upstream)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be neat if there was a config that would allow to provide an [ pkgs.foo pkgs.bar ] list.

(after this is PR is in, as it complements the needed basics)

hzeller added a commit to hzeller/bazel-python-test that referenced this pull request Feb 16, 2026
Comment thread pkgs/by-name/ba/bazel_8/package.nix Outdated
# ],
# )
[
bash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and for this one what's a rough issue repro scenario?

@hzeller hzeller Feb 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen it a bunch of times, e.g. with the OpenROAD test above (that hits both, the python3 and the bash problem

So even with python3 enabled but no bash, the following will fail:

bazel test -c opt //src/gpl/test:simple08

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took some time to clone-checkout-build but repro-ed this one too 👍

$ bazel build @@sed+//:lib/stdlib_h_inline
...
ERROR: ...../external/sed+/BUILD.bazel:108:15: RunBinary external/sed+/lib/stdlib.h failed: (Exit 127): inline_bin.sh failed: error executing RunBinary command (from target @@sed+//:lib/stdlib_h_inline) bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/sed+/inline_bin.sh bazel-out/k8-opt/bin/external/sed+/lib/stdlib.h.pre_inline bazel-out/k8-opt/bin/external/sed+/lib/stdlib.h ... (remaining 10 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
env: 'bash': No such file or directory

and that target definition is

external/sed+/BUILD.bazel:108:15
run_binary(
  name = "lib/stdlib_h_inline",
  tool = "@@sed+//:inline_sh",
  srcs = ["@@sed+//:lib/stdlib.h.pre_inline", "@@sed+//:lib/_Noreturn.h", "@@sed+//:lib/arg-nonnull.h", "@@sed+//:lib/c++defs.h", "@@sed+//:lib/static_assert.h", "@@sed+//:lib/warn-on-use.h"],
  outs = ["@@sed+//:lib/stdlib.h"],
  args = ["$(execpath lib/stdlib.h.pre_inline)", "$(execpath lib/stdlib.h)", "$(execpath lib/arg-nonnull.h)", "definition of _GL_ARG_NONNULL", "$(execpath lib/warn-on-use.h)", "definition of _GL_WARN_ON_USE", "$(execpath lib/_Noreturn.h)", "definition of _Noreturn", "$(execpath lib/c++defs.h)", "definitions of _GL_FUNCDECL_RPL", "$(execpath lib/static_assert.h)", "definition of static_assert"],
)

in turn @@sed+//:inline_sh is just a script with #!/usr/bin/env bash, it can be run via bazel run but fails in build action. Don't see a quick workaround here, well, except for

$ bazel build --action_env=PATH=/run/current-system/sw/bin @@sed+//:lib/stdlib_h_inline

Not sure yet this should be recommended, so adding some bash would be a path for now..

@hzeller

hzeller commented Feb 21, 2026

Copy link
Copy Markdown
Contributor Author

Ready to approve ? (I really would like to use bazel 8 without having to maintain local patches to my nixpkgs :) ).

I think after that (if you're interested) we should start discussing how we can make the bazel world more pleasant to use

  • On Nix, e.g. easy ways to inject dependencies if needed) and
  • Upstream bazel : generally make it less hermeticity-leaky

(e.g. I want to carve out some time to get Nix as a CI platform that is used for BCR bazelbuild/continuous-integration#2460 )

@lromor

lromor commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Would love to see this merged too!

Comment thread pkgs/by-name/ba/bazel_8/package.nix Resolved
Comment thread pkgs/by-name/ba/bazel_8/package.nix Resolved
@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Feb 24, 2026
@hzeller
hzeller force-pushed the feature-20260211-add-crucial-shell branch from b75357a to 30162d5 Compare February 25, 2026 19:19
A lot of parts of bazel and standard packages ssume bash existence;
they should be able to call `/usr/bin/env bash`.

Also, `rules_python` uses python3 as a bootstrap way to call
other scripts (even if it uses its own interpreter).

Both of these are important and have been in the
bazel 7 package
  https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/ba/bazel_7/package.nix#L87-L104
... but got lost in the bazel_8 package.

Things that used to compile with bazel 7 now break with bazel 8 on nix.

So: re-adding these crucial packages to the shell environment
bazel has available when executing actions.
@hzeller
hzeller force-pushed the feature-20260211-add-crucial-shell branch from 30162d5 to 1b7bce4 Compare February 25, 2026 19:35
@lromor
lromor self-requested a review March 5, 2026 22:49
@nixpkgs-ci nixpkgs-ci Bot removed the 12.approvals: 1 This PR was reviewed and approved by one person. label Mar 5, 2026
@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 2 This PR was reviewed and approved by two persons. label Mar 5, 2026
@hzeller

hzeller commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

Adding @samuela as we need someone who has the merge bit, and you were recently involved in other bazel-related merges.

@samuela

samuela commented Mar 12, 2026

Copy link
Copy Markdown
Member

I am not familiar with the details of this PR, but I will merge noting @boltzmannrain has approved it and is a maintainer for the derivation

@samuela
samuela added this pull request to the merge queue Mar 12, 2026
Merged via the queue into NixOS:master with commit 23bb7d5 Mar 12, 2026
28 of 30 checks passed
@3541 3541 mentioned this pull request Mar 14, 2026
6 of 11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants