Addition of a Flake.nix for Reth
For those unfamiliar with the Nix Package Manager, this is a Nix based file, with various features. Within this PR I made a working Proof of Concept for Reth.
Within the file, there are two features of the flake, a build system and a portable environment.
Seamless Build
- In an isolated environment(dependencies don't interact with other system files)
- Without cloning
Examples
When inside of the reth directory
$ nix build
Without downloading the repo
$ nix build "github:smolPatches/reth?ref=feat/reth-flake"
Portable Environment
- Allows users to easily pull down the dependencies of reth in one go
Required Rust Version, Cargo Dependencies, Clang, etc.
- Seamless environment to experiment w/ building / changing reth code
Examples
When inside of the reth directory
$ nix develop
Without downloading the repo
$ nix develop "github:smolPatches/reth?ref=feat/reth-flake"
Later, I will be making a PR to Nixpkgs as well to add Reth as a Nixpkg for users to install.
NOTE: I edited the rust-version in Cargo.toml because the official Rust Version on Rust's Page is 1.81.0 and I am parsing the Cargo.toml to select the right version of Rust to use within the Flake.
rustPlatform = pkgs.makeRustPlatform {
rustc = pkgs.rust-bin.stable."${rustVersion}".default;
cargo = pkgs.rust-bin.stable."${rustVersion}".default;
};
ping @Rjected, seems this is waiting for ur review
Oops looks like this wasn't highly demanded.
@Rjected @mattsse Maybe we can start with this single minimal shell.nix file?
let
pkgs =
import
# Unstable channel for now for Rust 1.86
(fetchTarball "https://github.com/NixOS/nixpkgs/archive/6b1c028bce9c89e9824cde040d6986d428296055.tar.gz")
{ };
in
pkgs.mkShell {
packages = with pkgs; [
cargo
cargo-nextest
rustPlatform.bindgenHook # For MDBX binding
];
hardeningDisable = [ "fortify" ]; # This Nix-injected flag breaks jemalloc debug build
}
If so, I can open a PR and help maintain it in a foreseeable future :pray:.
@hai-rise Just an opinion but if you are going to do it that way, you could use the same devShell in a flake.nix and shell.nix. So users can choose which they prefer.
@hai-rise Also it might be good if we used a overlay because if Reth decides to use a custom rust channel or toolchain that isn't yet in nixpkgs. This way the Rust version the devShell exports is closer tied to Reth's choices and not whatever is available in Nixpkgs at that moment.
@SmolPatches All good points! Nevertheless, at that point, we'd get close to this PR which is unfortunately yet understandably stuck.
My suggestion is a compromise to start with a minimal shell (15 lines) with a comment for each unobvious config, in hope it's so readable & small the maintainers would feel comfortable merging.
For fancier Nix, guess we'll need to bring in more Nix-using contributors to first raise the demand :slightly_smiling_face:.
@hai-rise @SmolPatches
The reason why I did not merge this PR is that I am not a nixos user any more, so I wouldn't be able to test or review any changes to the flake. So I don't have any super strong opinions on the contents of the flake / shell for direnv or whatever. It could be a good idea in theory, at least if it allows reth to be distributed via nixpkgs easily. I would however need a commitment on maintenance and review of the nix files, in case people actually start using it
@Rjected That's fair. I'm on NixOS but would also not be able to maintain Nix stuff I don't use. For Reth, currently, I only need that minimal shell (15 lines) for occasional contributions and can help maintain it.
I recently started using Nix on macOS with nix-darwin, so I can test it.
- It outputs some warnings that can be fixed
❯ nix build
warning: Git tree '/Users/shekhirin/projects/oss/reth' has uncommitted changes
warning: Flake input 'nixpkgs' uses the flake registry. Using the registry in flake inputs is deprecated in Determinate Nix. To make your flake future-proof, add the following to '/Users/shekhirin/projects/oss/reth/flake.nix':
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
For more information, see: https://github.com/DeterminateSystems/nix-src/issues/37
warning: updating lock file "/Users/shekhirin/projects/oss/reth/flake.lock":
• Updated input 'rust-overlay/nixpkgs':
'github:NixOS/nixpkgs/18dd725c29603f582cf1900e0d25f9f1063dbf11?narHash=sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38%3D' (2025-04-13)
→ follows 'nixpkgs'
evaluation warning: darwin.apple_sdk_11_0.Security: these stubs do nothing and will be removed in Nixpkgs 25.11; see <https://nixos.org/manual/nixpkgs/stable/#sec-darwin> for documentation and migration instructions.
evaluation warning: darwin.apple_sdk_11_0.CoreFoundation: these stubs do nothing and will be removed in Nixpkgs 25.11; see <https://nixos.org/manual/nixpkgs/stable/#sec-darwin> for documentation and migration instructions.
evaluation warning: darwin.apple_sdk_11_0.CoreServices: these stubs do nothing and will be removed in Nixpkgs 25.11; see <https://nixos.org/manual/nixpkgs/stable/#sec-darwin> for documentation and migration instructions.
- It rebuilds the whole project on every run, is that expected behaviour? I would assume it needs to use some caching.
@SmolPatches @hai-rise would appreciate your look, guys 😄
Also tested direnv, works good
direnv: loading ~/projects/oss/reth/.envrc
direnv: using flake .
direnv: nix-direnv: Using cached dev shell
direnv: export +AR +AR_FOR_TARGET +AS +AS_FOR_TARGET +CC +CC_FOR_TARGET +CONFIG_SHELL +CXX +CXX_FOR_TARGET +DEVELOPER_DIR +HOST_PATH +IN_NIX_SHELL +LD +LD_DYLD_PATH +LD_FOR_TARGET +LIBCLANG_PATH +MACOSX_DEPLOYMENT_TARGET +NIX_APPLE_SDK_VERSION +NIX_BINTOOLS +NIX_BINTOOLS_FOR_TARGET +NIX_BINTOOLS_WRAPPER_TARGET_HOST_arm64_apple_darwin +NIX_BINTOOLS_WRAPPER_TARGET_TARGET_arm64_apple_darwin +NIX_BUILD_CORES +NIX_CC +NIX_CC_FOR_TARGET +NIX_CC_WRAPPER_TARGET_HOST_arm64_apple_darwin +NIX_CC_WRAPPER_TARGET_TARGET_arm64_apple_darwin +NIX_CFLAGS_COMPILE +NIX_CFLAGS_COMPILE_FOR_TARGET +NIX_DONT_SET_RPATH +NIX_DONT_SET_RPATH_FOR_BUILD +NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE +NIX_IGNORE_LD_THROUGH_GCC +NIX_LDFLAGS +NIX_LDFLAGS_FOR_TARGET +NIX_NO_SELF_RPATH +NIX_STORE +NM +NM_FOR_TARGET +OBJCOPY +OBJCOPY_FOR_TARGET +OBJDUMP +OBJDUMP_FOR_TARGET +PATH_LOCALE +RANLIB +RANLIB_FOR_TARGET +RUST_SRC_PATH +SDKROOT +SIZE +SIZE_FOR_TARGET +SOURCE_DATE_EPOCH +STRINGS +STRINGS_FOR_TARGET +STRIP +STRIP_FOR_TARGET +ZERO_AR_DATE +__darwinAllowLocalNetworking +__impureHostDeps +__propagatedImpureHostDeps +__propagatedSandboxProfile +__sandboxProfile +__structuredAttrs +buildInputs +buildPhase +builder +cmakeFlags +configureFlags +depsBuildBuild +depsBuildBuildPropagated +depsBuildTarget +depsBuildTargetPropagated +depsHostHost +depsHostHostPropagated +depsTargetTarget +depsTargetTargetPropagated +doCheck +doInstallCheck +dontAddDisableDepTrack +hardeningDisable +mesonFlags +name +nativeBuildInputs +out +outputs +patches +phases +preferLocalBuild +propagatedBuildInputs +propagatedNativeBuildInputs +shell +shellHook +stdenv +strictDeps +system ~PATH
projects/oss/reth on feat/reth-flake [$?] via 🐳 orbstack is 📦 v1.5.1 via 🦀 v1.88.0 via ❄️ impure (nix-shell-env)
❯ cargo b --quiet
projects/oss/reth on feat/reth-flake [$?] via 🐳 orbstack is 📦 v1.5.1 via 🦀 v1.88.0 via ❄️ impure (nix-shell-env) took 1m22s
❯ cat .envrc
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: .envrc
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ use flake .
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────
From what I found, buildRustPackage can't really do caching because it doesn't build crate by crate: https://discourse.nixos.org/t/rustplatform-buildrustpackage-and-caching/11138
Should we just use crate2nix or naersk instead? (classic nix, 12983671298312 ways to do the same thing)
It may be not an issue, since we won't be using Nix for our CI (anytime soon / ever), and when you use the shell, you get caching.
@shekhirin Oh Nix on macOS, I hope your disk is ready!
Anyway, I'm using this bare minimum shell for Reth works:
let
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-25.05.tar.gz") { };
in
pkgs.mkShell {
packages = with pkgs; [
cargo
cargo-nextest
rustfmt
rustPlatform.bindgenHook # For MDBX binding
];
hardeningDisable = [ "fortify" ]; # This Nix-injected flag breaks jemalloc debug build
}
So no comment on a Flake one. Also note that both this and the PR don't use the nightly formatter, which can be a bit annoying.
Also note that both this and the PR don't use the nightly formatter, which can be a bit annoying.
yeah that's why I do this https://github.com/SmolPatches/reth/blob/3cbd40ceb295bea6971d7a991cfa31ba241a074d/flake.nix#L86-L91
@shekhirin @hai-rise @SmolPatches I've reworked the flake in this PR to be based on fenix+crane, which I've found to be more reliable these days. My branch is here:
https://github.com/paradigmxyz/reth/tree/mediocregopher/reth-flake
If someone with a mac could test building developing with it, that'd be great, I can only confirm it works on Linux.
# Dev shell
nix develop 'github:paradigmxyz/reth/mediocregopher/reth-flake'
# Build reth
nix build 'github:paradigmxyz/reth/mediocregopher/reth-flake'
# Build op-reth
nix build 'github:paradigmxyz/reth/mediocregopher/reth-flake#op-reth'
I have enabled the mold linker only on linux, if you want to try it out you can move the withMold overrides outside the linux optionals. Making that the default would be great.
Put my flake.nix in a new PR here: https://github.com/paradigmxyz/reth/pull/17757
Superseded by https://github.com/paradigmxyz/reth/pull/17757.