Skip to content

Conversation

@hazelnusse
Copy link
Collaborator

/bin/bash is unavailable on NixOS by default. This breaks many bazel assumptions and causes build failures such as:

  ...
  process-wrapper-legacy.cc:80: "execvp(/bin/bash, ...)": No such file or directory
  ...

By unsetting incompatible_strict_action_env 0, conditionally (on NixOS) setting shell_executable 1 to the bash in the Nix store, and by setting the bazel-wrapper PATH with
writeShellApplication.runtimeInputs we are able to avoid these errors.

Finally, tag several targets in //example as "manual" so they are not automatically built with the host toolchain, since this currently fails on NixOS. This should be addressed in a follow-up commit.

Testing was performed using nixpkgs supplied bazelisk 3 on Luke Peterson's and Michael Schneider's NixOS machines. This itself presented issues, as this package is documented with BEWARE: This package does not work on NixOS. Out of the box this is true, but can be worked around with programs.nix-ld.enable = true 4 in configuration.nix.

Special thanks to Oliver Lee and Michael Schneider during the final day of Nixcademy NixOS training. This was a great collaboration!

@hazelnusse
Copy link
Collaborator Author

@m1-s thank you for all your help on this! @oliverlee and I hacked on it for a few more hours after class and came up with a different strategy that seems to avoid a corner case we hit after class (and at this hour, I can't even remember what it was, but it was 🤯). If you have the time and inclination, we'd love to have your feedback but no worries if not! Thank you again!

@hazelnusse hazelnusse force-pushed the make_nixos_great_again branch 3 times, most recently from 5577970 to 69aa51e Compare August 30, 2025 05:26
@oliverlee
Copy link
Owner

The nix store path was only valid for linux-x86_64, so this would fail on other systems (e.g. darwin-aarch64).

oliverlee
oliverlee previously approved these changes Aug 30, 2025
Copy link
Owner

@oliverlee oliverlee left a comment

Choose a reason for hiding this comment

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

Maybe update the develop section of the readme with NixOS config requirements.

It looks like forks don't have access to secrets. I'll try and fix that this weekend unless you do it before I do.

@hazelnusse hazelnusse force-pushed the make_nixos_great_again branch from 69aa51e to e08694d Compare August 31, 2025 03:56
@hazelnusse
Copy link
Collaborator Author

The nix store path was only valid for linux-x86_64, so this would fail on other systems (e.g. darwin-aarch64).

Please take a look at how I did this and try on darwin-aarch64 to make sure you get an empty .nixos-autoconfig/bazelrc?

@oliverlee
Copy link
Owner

Thanks! No .nixos-autoconfig/bazelrc for me.

See inline comments and you'll need to sign your commit:
https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

@oliverlee oliverlee self-requested a review August 31, 2025 19:59
@oliverlee oliverlee dismissed their stale review August 31, 2025 20:01

Does bazelisk run //tools:format work for you? I'm getting the following error in my NixOS VM:

INFO: Running command line: bazel-bin/tools/format.bash
/home/builder/.cache/bazel/_bazel_builder/98502806d288a25787a2b73a84a8c1a8/execroot/_main/bazel-out/aarch64-fastbuild/bin/tools/format.bash: line 19: /home/builder/.cache/bazel/_bazel_builder/98502806d288a25787a2b73a84a8c1a8/execroot/_main/bazel-out/aarch64-fastbuild/bin/tools/format.bash.runfiles/rules_multirun+/internal/multirun: cannot execute: required file not found
@oliverlee
Copy link
Owner

bazel run //tools:format currently doesn't work on NixOS.

The target is defined by the multirun rule which defines a Python script. rules_python is pulled in and configured to use a bootstrap script to provide the hermetic Python interpreter. It looks like the issue has already been fixed but we'll need to update the commit we use:
bazel-contrib/rules_python#3087

@hazelnusse hazelnusse force-pushed the make_nixos_great_again branch 4 times, most recently from f842c24 to 834ebd5 Compare September 2, 2025 19:24
/bin/bash is unavailable on NixOS by default. This breaks many bazel
assumptions and causes build failures such as:

```
  ...
  process-wrapper-legacy.cc:80: "execvp(/bin/bash, ...)": No such file or directory
  ...
```

By unsetting `incompatible_strict_action_env` [0], conditionally (on
NixOS) setting `shell_executable` [1] to the bash in the Nix store, and
by setting the `bazel-wrapper` PATH with
`writeShellApplication.runtimeInputs` we are able to avoid these errors.

Finally, tag several targets in //example as "manual" so they are not
automatically built with the host toolchain, since this currently fails
on NixOS. This should be addressed in a follow-up commit.

Testing was performed using nixpkgs supplied bazelisk [3] on Luke
Peterson's and Michael Schneider's NixOS machines. This itself presented
issues, as this package is documented with `BEWARE: This package does
not work on NixOS.` Out of the box this is true, but can be worked
around with `programs.nix-ld.enable = true` [4] in `configuration.nix`.

Special thanks to Oliver Lee and Michael Schneider during the final day
of Nixcademy NixOS training. This was a great collaboration!

[0]: https://bazel.build/reference/command-line-reference#flag--incompatible_strict_action_env
[1]: https://bazel.build/reference/command-line-reference#flag--shell_executable
[2]: https://nixos.org/manual/nixpkgs/unstable/#trivial-builder-writeShellApplication
[3]: https://github.com/NixOS/nixpkgs/blob/nixos-25.05/pkgs/by-name/ba/bazelisk/package.nix
[4]: https://github.com/nix-community/nix-ld
@hazelnusse hazelnusse force-pushed the make_nixos_great_again branch from 834ebd5 to 6707a64 Compare September 2, 2025 20:13
@hazelnusse hazelnusse enabled auto-merge (squash) September 2, 2025 20:25
@hazelnusse hazelnusse merged commit c955695 into oliverlee:main Sep 2, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants