Skip to content

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

Terminal window
nix flake init -t github:TraceMachina/nativelink#TEMPLATE_NAME
git init
git 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://TODO
build --remote_header=x-nativelink-api-key=TODO
build --bes_backend=grpcs://TODO
build --bes_header=x-nativelink-api-key=TODO
build --bes_results_url=TODO
build --remote_timeout=600
build --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 under packages. 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 in MODULE.bazel, the URL to the container image in platforms/BUILD.bazel, and update the flake inputs with nix flake update. Upon changes, don’t forget to re-enter the Nix environment with nix develop.

  • user.bazelrc: Add Bazel flags to your builds, see Command-Line Reference. Don’t forget to add your NativeLink cloud credentials or set remote_cache and remote_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 platform lre-cc specifies the URL of the container-image that gets passed to the NativeLink cloud with exec_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 with pre-commit run -a.

  • .github/workflows: Contains pre-configured GitHub workflows for pre-commit hooks and building your project.