Nix templates
NativeLink provides the following templates to use caching and remote execution on the NativeLink cloud:
bazel
: C++ with local remote execution using Bazel. Provides the same toolchain during local and remote execution to share cache between those builds. Currently restricted to Linux. See Local Remote Execution for further details.
Install Nix
with flakes
enabled, for instance install it via
experimental-nix-installer.
Create a new directory, cd
into it and replace TEMPLATE_NAME
with the name
of the template to initialize your project with
nix flake init -t github:TraceMachina/nativelink#TEMPLATE_NAMEgit initgit add .
Enter the Nix environment with nix develop
.
Optionally install direnv
and create .envrc
containing
use flake
to automatically enter the development environment.
Get your credentials for the NativeLink cloud and
paste them into user.bazelrc
build --remote_cache=grpcs://TODObuild --remote_header=x-nativelink-api-key=TODObuild --bes_backend=grpcs://TODObuild --bes_header=x-nativelink-api-key=TODObuild --bes_results_url=TODObuild --remote_timeout=600build --remote_executor=grpcs://TODO
You’re ready to build the provided example with bazel build hello-world
.
-
flake.nix
: Add development tools and build dependencies underpackages
. If you add build dependencies, add them to the RBE image and update the image URL. If you change the NativeLink input to another git hash, adjust the URL of the LRE Bazel module inMODULE.bazel
, the URL to the container image inplatforms/BUILD.bazel
, and update the flake inputs withnix flake update
. Upon changes, don’t forget to re-enter the Nix environment withnix develop
. -
user.bazelrc
: Add Bazel flags to your builds, see Command-Line Reference. Don’t forget to add your NativeLink cloud credentials or setremote_cache
andremote_executor
to your on-prem solution, see remote execution infrastructure. -
BUILD.bazel
: The top level Bazel build file, see C/C++ Rules. -
platforms/BUILD.bazel
: The platformlre-cc
specifies the URL of thecontainer-image
that gets passed to the NativeLink cloud withexec_properties
. This platform inherits its properties from the LRE Bazel module.
-
pre-commit-hooks.nix
: Configure linting and formatting for CI, see available hooks. You can manually call them withpre-commit run -a
. -
.github/workflows
: Contains pre-configured GitHub workflows for pre-commit hooks and building your project.