Nix flake module
The NativeLink Cloud flake module lets your contributors conveniently reuse artifacts from your CI builds.
Prerequisites
Cache sharing between CI and local development environments requires perfect reproducibility between the two.
Consider using Local Remote Execution to create environments that are reproducible across distributions.
Containerized environments that are the same for local development and CI might work as well.
Setup
-
Add the
nativelink
flake module to your flake:flake.nix # In your flake inputs:inputs.nativelink.url = "github:TraceMachina/nativelink";# In your flake-parts.lib.mkFlake imports:imports = [nativelink.flakeModule];# In your shellHook:devShells.default = pkgs.mkShell {shellHook = ''# Generate nativelink.bazelrc which gives Bazel invocations access# to NativeLink's read-only cache.${config.nativelink.installationScript}''; -
Add the following to your
.bazelrc
:.bazelrc try-import %workspace%/nativelink.bazelrc -
Ignore the generated file:
.gitignore nativelink.bazelrc -
Optionally, customize the endpoint and API key, or gate the configuration behind a
--config=nativelink
Bazel flag:flake.nix nativelink.settings = {endpoint = "grpcs://my-custom-endpoint.com";api-key = "my-custom-readonly-api-key";prefix = "nativelink";};
How it works
The nativelink
flake module creates a nativelink.bazel
file. The default
configuration points to NativeLink’s public cache:
# These flags are dynamically generated by the nativelink flake module.## Add `try-import %workspace%/nativelink.bazelrc` to your .bazelrc to# include these flags when running Bazel in a nix environment.
build --remote_cache=grpcs://cas-tracemachina-shared.build-faster.nativelink.netbuild --remote_header=x-nativelink-api-key=065f02f53f26a12331d5cfd00a778fb243bfb4e857b8fcd4c99273edfb15deaebuild --remote_instance_name=mainbuild --remote_header=x-nativelink-project=nativelink-cibuild --nogenerate_json_trace_profilebuild --remote_upload_local_results=falsebuild --experimental_remote_cache_async
With the modifications from the previous section it looks like this:
# These flags are dynamically generated by the nativelink flake module.## Add `try-import %workspace%/nativelink.bazelrc` to your .bazelrc to# include these flags when running Bazel in a nix environment.
build:nativelink --remote_cache=grpcs://my-custom-endpoints.combuild:nativelink --remote_header=x-nativelink-api-key=my-custom-readonly-api-keybuild:nativelink --remote_header=x-nativelink-project=nativelink-cibuild:nativelink --nogenerate_json_trace_profilebuild:nativelink --remote_upload_local_results=falsebuild:nativelink --experimental_remote_cache_async