feat: add Nix crane build system with Cachix caching - #270
Draft
radupopa369 wants to merge 20 commits into
Draft
Conversation
- Add crane input for reproducible Rust builds via Nix - Add package outputs for all 5 binaries: - aptos-node, movement, l1-migration - aptos-faucet-service, aptos-transaction-emitter - Add all-binaries aggregate package - Add container outputs using dockerTools (Linux only) - Add Cachix substituter configuration for movementlabsxyz - Add Justfile recipes: build-nix, build-all-nix, container-nix, container-load, container-push - Add comprehensive documentation in docs/nix-build-setup.md and docs/nix-cachix-setup.md - Support dual platform builds: aarch64-darwin and x86_64-linux - Platform-specific RUSTFLAGS (SSE4.2 only on x86_64)
- Update nixpkgs from pinned commit to nixos-unstable (required by crane 25.11+) - Migrate from deprecated darwin.apple_sdk.frameworks to new apple-sdk_15 pattern - Remove libelf dependency (now provided by SDK) - Reference: https://discourse.nixos.org/t/the-darwin-sdks-have-been-updated/55295
- Focus on trusted-users setup (the actual fix for warnings) - Remove cachix CLI instructions (cache not yet created) - Add Determinate Nix specific instructions - Clarify current cache status
- Add cache-push, cache-push-all, cache-status recipes to Justfile - Rewrite docs/nix-cachix-setup.md with complete workflow: - One-time admin setup (create cache, generate tokens) - Developer setup (trusted-users, install cachix CLI) - PR review workflow (author pushes, reviewer pulls) - CI/CD integration example Enables team members to share builds during PR review to avoid redundant compilation.
Update from 'movementlabsxyz' to 'movementlabs' which is the existing cache. Update public key to: movementlabs.cachix.org-1:qqCkWyzFSZCH2TcyHPRXVOOlYR3Sv+4GKMXSZtyN8s=
Use group-based trust (@admin @staff) instead of individual usernames for Determinate Systems' Nix on macOS. Individual usernames don't work reliably even when configured correctly. Also include full nix.custom.conf with: - trusted-substituters for Cachix - trusted-public-keys for cache verification - accept-flake-config for automatic flake nixConfig acceptance
…y error - Add Nix build section to README with quick start and feature comparison - Update nix-build-setup.md to strongly recommend Determinate Nix - Add feature comparison table (parallel eval, lazy trees, native Linux builder) - Document upgrade command: sudo determinate-nixd upgrade - Add workaround for 'public key is not valid' error in cachix setup
- Add .github/workflows/nix-build.yaml for CI-based builds - Add cache-watch and cache-build Justfile recipes for local builds - Both CI and local push to same movementlabs Cachix cache - Update cache-status to check config file existence
…rrors The 'public key is not valid' error occurs with some Nix versions when the Cachix key is specified in flake.nix. Moving configuration to system config (/etc/nix/nix.custom.conf) avoids this issue. Cachix still works via: - System config for local builds - cachix-action for CI builds
Determinate Nix adds FlakeHub cache keys to /etc/nix/nix.conf which can trigger a key validation error. Document the fix: comment out the extra-trusted-public-keys line containing FlakeHub keys. Updated: - README.md: Quick troubleshooting note - docs/nix-build-setup.md: Detailed fix instructions - docs/nix-cachix-setup.md: Troubleshooting section and updated flake config docs
Add patterns for files embedded via include_str!/include_bytes! macros: - .json files (JWKS test keys) - .pem files (cryptographic keys) - .bpl files (Boogie prover prelude) - .mv files (Move bytecode) These files were being filtered out by craneLib.filterCargoSources, causing build failures for l1-migration and other packages.
Move stdlib uses include_bytes! for error_description.errmap file.
Config crate uses include_str! for test_data YAML files.
The movementlabs Cachix public key was missing a '/' character. Correct key: movementlabs.cachix.org-1:qqCkWyzFSZCH2Tcy/HPRXVOOlYR3Sv+4GKMXSZtyN8s=
The crate was renamed from 'aptos' to 'movement' in Cargo.toml
These files are embedded at compile time via include_str!: - test_proofs_for_localnet_txn_emitter.txt - doc/spec.html (API documentation) - doc/.version (version info)
On macOS, system jemalloc doesn't have the _rjem_ prefixed symbols that jemallocator crate expects. Let jemalloc-sys build from source on macOS to get the correct prefixed symbols.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR transitions the aptos-core build system from
nix develop -c cargo buildto propernix build .#<package>pattern using crane, enabling:Problem
The current build system uses
nix develop -c cargo buildwhich:Solution
The new system uses
nix build .#<package>which:/nix/store/...)Changes
Files Modified/Created
nix/flake.nixnix/flake.lockJustfilebuild-nix,build-all-nix,container-nix,cache-*recipesdocs/nix-build-setup.mddocs/nix-cachix-setup.md.github/workflows/nix-build.yamlNew Build Targets
aptos-nodejust build-nix aptos-nodemovementjust build-nix movementl1-migrationjust build-nix l1-migrationaptos-faucet-servicejust build-nix aptos-faucet-serviceaptos-transaction-emitterjust build-nix aptos-transaction-emitterall-binariesjust build-all-nixContainer Targets (Linux only)
container-aptos-nodejust container-nix aptos-nodecontainer-aptos-faucet-servicejust container-nix aptos-faucet-serviceHow to Test
Prerequisites
Determinate Nix adds FlakeHub cache keys that can cause validation errors. Fix by editing
/etc/nix/nix.conf:Find and comment out or remove the line starting with:
Then restart the daemon:
macOS:
sudo launchctl stop org.nixos.nix-daemon && sudo launchctl start org.nixos.nix-daemonLinux:
macOS:
Test Build Commands
Automated Cache Population
Both CI and local builds push to the same Cachix cache:
CI (GitHub Actions)
The
.github/workflows/nix-build.yamlworkflow automatically:movementlabsCachix cacheRequired Secret: Add
CACHIX_AUTH_TOKENto repository secrets.Local Development
Option 1: Auto-push while developing (recommended)
Run in a separate terminal - automatically pushes ALL nix builds to cache:
Option 2: Build and push specific binary
Option 3: Manual push after building
Verify Cache Hits
After pushing, subsequent builds should pull from cache:
rm -f result nix build .#aptos-node -LYou'll see cache hits in the output:
Related Issues
Closes #227
Out of Scope (Future Work)