Skip to content

tweag/buck2.nix

Repository files navigation

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

Sponsors

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

License

Apache 2.0

About

Buck2 rules for Nix

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published