SkillAgentSearch skills...

Buck2.nix

Buck2 rules for Nix

Install / Use

/learn @tweag/Buck2.nix
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

buck2.nix

Integrate Nix with Buck2 to configure toolchains and dependencies for a project.

Motivation

Buck2 is a polyglot build system that is designed to be fast and efficient for large codebases. Buck2 relies on remote execution for build isolation to enforce hermetic builds, therefore does not isolate local build actions so strictly.

Nix is a powerful package manager and build system for Linux and other Unix-like operating systems which strives for reproducibility. The nixpkgs repository is a very comprehensive, large collection of software packaged using nix.

By integrating Nix with Buck2 and leveraging the nixpkgs package collection, a project can define its required build tools and toolchains (e.g. C++, Python, Rust) declaratively and reproducibly but still benefit from fast, reliable builds.

Quickstart

To create a project using buck2.nix, run:

$ nix flake new --template github:tweag/buck2.nix quickstart

To build the project, run:

$ cd quickstart
$ nix develop
$ buck2 build ...

Note: if you use direnv, just run direnv allow in the project directory.

Usage

  1. add it to you .buckconfig setting the commit hash to the current main branch:
[external_cells]
nix = git

[external_cell_nix]
git_origin = https://github.com/tweag/buck2.nix.git
commit_hash = ...
  1. add a nix flake to your project

e.g. in tools/nix/flake.nix:

outputs = { ... }: {
  packages.${system}.python = python3;
}
  1. use it in your project

in tools/BUCK:

load("@nix//flake.bzl", "flake")

flake.package(
    name = "python"
    binary = "python",
    path = "nix",
)

See the documentation and examples in examples/.

Links

  • https://github.com/thoughtpolice/buck2-nix -- alternative prelude using nix

Sponsors

buck2.nix was funded by Mercury Technologies and is maintained by Tweag

License

Apache 2.0

View on GitHub
GitHub Stars37
CategoryDevelopment
Updated4d ago
Forks1

Languages

Starlark

Security Score

90/100

Audited on Mar 25, 2026

No findings