Nix provides the recommended development environment for NativeLink. It ensures reproducible builds, matches the CI environment, and ships almost all development tooling in a single flake.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/TraceMachina/nativelink/llms.txt
Use this file to discover all available pages before exploring further.
Why Nix?
NativeLink uses Nix because it provides:- Reproducibility - Bit-for-bit identical builds across machines
- CI Parity - Same environment locally and in continuous integration
- Complete Tooling - All development tools in one place
- Declarative Setup - Environment defined in
flake.nix - Cross-Platform - Works on Linux, macOS, and WSL2
While Nix is optional, it’s highly recommended as it lets you reproduce most of CI locally.
Installation
Prerequisites
Install Nix with Flakes
Use the experimental nix installer which enables flakes by default:This installer automatically:
- Installs Nix
- Enables flakes and nix-command features
- Configures your shell
Install direnv (Highly Recommended)
direnv automatically loads the Nix environment when you enter the repository:Hook direnv into your shell:See the direnv hook documentation for other shells.
- Bash
- Zsh
- Fish
Restart Your Terminal
After installing direnv and adding the hook, restart your terminal or source your shell configuration:
Verify Installation
Check Nix Environment
Verify the environment is active:You should see several
*NIX_* environment variables.Development Shell
Included Tools
The Nix development shell (defined inflake.nix:453-560) includes:
- Core Development
- Rust Tooling
- Infrastructure
- Container Tools
- Documentation
- Web Development
- git - Version control
- pre-commit - Git hooks for code quality
- git-cliff - Changelog generation
- buck2 - Alternative build system
flake.nix:454-520 for the complete list.
Shell Hook
When entering the development shell, several setup scripts run automatically (seeflake.nix:522-559):
Platform-Specific Config
Generates platform configs:
nixos.bazelrc(on NixOS)darwin.bazelrc(on macOS)
Building with Nix
Build Commands
Build Internals
NativeLink’s Nix build uses crane for Rust projects:- Build Arguments
- Dependency Caching
- Cross-Compilation
Common build arguments (see
flake.nix:98-155):Testing with Nix
Run Tests
Pre-commit Hooks
Pre-commit hooks are configured via the Nix flake (seeflake.nix:409-414):
tools/pre-commit-hooks.nix and include:
- rustfmt (formatting)
- clippy (linting)
- vale (documentation)
- Various config generators
Development Workflow
Typical Workflow
Using Bazel in Nix
The Nix shell provides a Bazel wrapper (seeflake.nix:455-458):
Advanced Features
Local Remote Execution (LRE)
Nix provides LRE toolchains automatically (seeflake.nix:416-425):
lre.bazelrc by the shell hook.
Custom Packages
The flake exports several custom packages (seeflake.nix:336-398):
nativelink-worker-*
Worker images for different toolchains:
- lre-cc (C++ toolchain)
- lre-rs (Rust toolchain)
- lre-java (Java toolchain)
- siso-chromium (Chromium builds)
Integration Tests
- buildstream-with-nativelink-test
- mongo-with-nativelink-test
- buck2-with-nativelink-test
- rbe-toolchain-with-nativelink-test
Utilities
- generate-bazel-rc
- generate-stores-config
- update-module-hashes
- local-image-test
Flake Apps
The flake provides runnable apps (seeflake.nix:325-334):
Documentation Generation
Generate documentation using thedocs command:
docs package is defined at tools/docs.nix.
Troubleshooting
direnv not loading environment
direnv not loading environment
Check direnv status:Ensure you ran
direnv allow in the repository.If issues persist, manually enter the shell:Nix build fails with hash mismatch
Nix build fails with hash mismatch
Update flake inputs:Or rebuild without cache:
Out of disk space in /nix/store
Out of disk space in /nix/store
Collect garbage to free space:
macOS: Cannot find C++ compiler
macOS: Cannot find C++ compiler
Install Xcode Command Line Tools:The Nix environment doesn’t ship a full C++ toolchain.
Nix commands hang or are very slow
Nix commands hang or are very slow
Check Nix daemon status:Or rebuild Nix database:
Platform-Specific Notes
Linux
- Builds use musl for static linking
- LRE fully supported with C++ and Rust toolchains
- Uses mold linker for fast linking (see
flake.nix:120)
macOS
- No cross-compilation support (must build natively)
- LRE uses Rust toolchain only (C++ not yet supported)
- Requires Xcode Command Line Tools
- Uses lld linker (see
flake.nix:121) - Darwin-specific frameworks included automatically (see
flake.nix:512-516)
NixOS
- Special PATH configuration for LRE (see
flake.nix:426-452) - Generates
nixos.bazelrcwith correct binary paths - Fully integrated with system Nix configuration
Resources
Nix Manual
Official Nix documentation
Nix Flakes
Flakes reference and guide
crane
Nix library for Rust projects
direnv
Environment switcher for shells
Next Steps
Development with Bazel
Learn Bazel build system features
Development with Cargo
Use Cargo for fast iteration