Skip to content

nixos/bazelisk: add NixOS module; remove "does not work" warning#510826

Open
DhashS wants to merge 2 commits intoNixOS:masterfrom
DhashS:programs/bazelisk
Open

nixos/bazelisk: add NixOS module; remove "does not work" warning#510826
DhashS wants to merge 2 commits intoNixOS:masterfrom
DhashS:programs/bazelisk

Conversation

@DhashS
Copy link
Copy Markdown

@DhashS DhashS commented Apr 17, 2026

Summary

Add a programs.bazelisk NixOS module that makes bazelisk work on NixOS, and remove the BEWARE: This package does not work on NixOS warning from the bazelisk package meta.

Motivation

Bazelisk downloads unpatched Bazel binaries that fail on NixOS because:

  1. /bin/bash doesn't exist (or isn't resolvable with an empty PATH)
  2. Common tools (touch, grep, etc.) aren't at FHS-standard paths
  3. rules_cc toolchain detection can't find a C compiler

The existing bazel_9 nix package solves this by building Bazel from source with 6+ patches, but that locks you to a single version. Bazelisk's whole purpose is version-switching via .bazelversion, which the patched package can't support.

What the module does

programs.bazelisk.enable = true sets up three things:

  1. Installs bazelisk with a bazel symlink so it's a drop-in replacement
  2. Enables envfs with bash in the fallback path, so /bin/bash resolves even when Bazel strips the environment (exec env -)
  3. Writes /etc/bazel.bazelrc with --action_env=PATH and --host_action_env=PATH pointing to Nix store paths for common tools (bash, coreutils, findutils, gawk, gnugrep, gnused, gnutar, gzip, which, unzip)

Optional cc/cxx options set --repo_env=CC/CXX for rules_cc toolchain detection. extraPackages and extraBazelrc allow further customization.

Example usage

programs.bazelisk = {
  enable = true;
  cc = "${pkgs.clang}/bin/clang";
  cxx = "${pkgs.clang}/bin/clang++";
};

Per-project settings (e.g. extra rustc flags, pkg-config paths) still go in .bazelrc.user.

Testing

Tested on a real-world Bazel project with Rust, TypeScript, and Swift rules — 27/27 targets building on both Bazel 9.0.1 and 9.0.2 by simply changing .bazelversion and letting bazelisk do its thing.

Note: there's a companion fix needed in bazel_env.bzl to replace touch with a bash builtin in one of its actions, but all other Bazel rules work out of the box.

Files changed

  • nixos/modules/programs/bazelisk.nix — new NixOS module
  • nixos/modules/module-list.nix — register the module
  • pkgs/by-name/ba/bazelisk/package.nix — update meta description

This PR was vibe coded with Claude Code.

@nixpkgs-ci nixpkgs-ci Bot requested a review from elasticdog April 17, 2026 09:02
@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: 0 This PR does not cause any packages to rebuild on Darwin. 12.first-time contribution This PR is the author's first one; please be gentle! 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Apr 17, 2026
@DhashS DhashS force-pushed the programs/bazelisk branch from 7a54175 to b8203bd Compare April 17, 2026 09:56
@DhashS DhashS force-pushed the programs/bazelisk branch 2 times, most recently from 409b98d to 0a3c520 Compare May 1, 2026 03:04
Add a programs.bazelisk NixOS module that installs bazelisk with a bazel symlink, enables envfs for /bin/bash compatibility, and writes /etc/bazel.bazelrc with Nix store paths for common Bazel action tools.

The module also supports optional CC/CXX settings for rules_cc detection, extra action PATH packages, and extra bazelrc lines. Add a NixOS test covering the generated bazelrc, envfs fallback, and bazel symlink, and link it from bazelisk.passthru.tests.
@DhashS DhashS force-pushed the programs/bazelisk branch from 0a3c520 to 0992abc Compare May 1, 2026 03:08
@nixpkgs-ci nixpkgs-ci Bot requested a review from GetPsyched May 1, 2026 03:15
@nixpkgs-ci nixpkgs-ci Bot added 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` 8.has: documentation This PR adds or changes documentation labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant