Integrate Nix with Buck2 to configure toolchains and dependencies for a project.
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.
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.
- 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 = ...
- add a nix flake to your project
e.g. in tools/nix/flake.nix
:
outputs = { ... }: {
packages.${system}.python = python3;
}
- 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/
.
- https://github.com/thoughtpolice/buck2-nix -- alternative prelude using nix
buck2.nix was funded by Mercury Technologies and is maintained by Tweag