From c62506be18dc8d1d5097c2c8fb988d5958b2e51a Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Sun, 11 Jan 2026 00:20:16 +0100 Subject: [PATCH 01/15] initial flake.nix --- .gitignore | 3 + flake.lock | 82 ++++ flake.nix | 152 +++++++ nix/cargo-near.nix | 63 +++ nix/near-cli-rs.nix | 51 +++ nix/py-arkworks-bls12381-lockfile.lock | 584 +++++++++++++++++++++++++ nix/python-env.nix | 222 ++++++++++ 7 files changed, 1157 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/cargo-near.nix create mode 100644 nix/near-cli-rs.nix create mode 100644 nix/py-arkworks-bls12381-lockfile.lock create mode 100644 nix/python-env.nix diff --git a/.gitignore b/.gitignore index b68b2a785b..dfe0aae1cd 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ venv # Files for launcher **/.app-compose.json + +# Nix cargo home +.nix-cargo/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..351ef02ad5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1767892417, + "narHash": "sha256-dhhvQY67aboBk8b0/u0XB6vwHdgbROZT3fJAjyNh5Ww=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3497aa5c9457a9d88d71fa93a4a8368816fbeeba", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay", + "utils": "utils" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1767926800, + "narHash": "sha256-x0n73J6ufD/EhDlVdcoAmF0OQHZ+b0a2cKDc8RZyt+o=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "499e9eed88ff9494b6604205b42847e847dfeb91", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..db38769d03 --- /dev/null +++ b/flake.nix @@ -0,0 +1,152 @@ +{ + description = "Rust development environment for NEAR (Workspace)"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + # Ensures rust-overlay uses the same nixpkgs version as this flake + inputs.nixpkgs.follows = "nixpkgs"; + }; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + rust-overlay, + utils, + }: + utils.lib.eachDefaultSystem ( + system: + let + # Use the recommended flake output for the overlay + overlays = [ rust-overlay.overlays.default ]; + pkgs = import nixpkgs { inherit system overlays; }; + + inherit (pkgs) lib; + llvmPkg = pkgs.llvmPackages_19; + + # Load toolchain from file and add necessary components + rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { + extensions = [ + "rust-src" + "rust-analyzer" + "clippy" + "rustfmt" + ]; + }; + + pythonEnv = import ./nix/python-env.nix { inherit pkgs; }; + + # Helper variables for Clang/LLVM paths + clangVersion = lib.versions.major llvmPkg.clang-unwrapped.version; + clangResourceDir = "${llvmPkg.clang-unwrapped.lib}/lib/clang/${clangVersion}/include"; + libcInc = lib.getDev pkgs.stdenv.cc.libc; + + # Near tools + cargo-near = pkgs.callPackage ./nix/cargo-near.nix { }; + near-cli-rs = pkgs.callPackage ./nix/near-cli-rs.nix { }; + in + { + devShells.default = pkgs.mkShell { + # strictDeps ensures that build-time tools and run-time libs are correctly separated + strictDeps = true; + + # Developer Tools + nativeBuildInputs = with pkgs; [ + pkg-config + llvmPkg.clang + llvmPkg.libclang + + # Rust + rustToolchain + rustPlatform.bindgenHook + + # Cargo extensions + cargo-binstall + cargo-deny + cargo-insta + cargo-make + cargo-nextest + cargo-shear + cargo-sort + + # wasm-opt + binaryen + + # Near CLI and SDK + near-cli-rs + cargo-near + + # python + pythonEnv + + # Various utilities + git + zizmor + ]; + + # Dynamic libraries required for build + buildInputs = + with pkgs; + [ + openssl + zlib + libiconv + snappy + lz4 + zstd + bzip2 + ] + ++ lib.optionals stdenv.isLinux [ + udev + dbus + ] + ++ lib.optionals stdenv.isDarwin [ + pkgs.apple-sdk + ]; + + env = { + # Needed for neard's librockdb build + # Apply x86-specific flags ONLY on x86_64 machines + CXXFLAGS = + let + isX86 = lib.strings.hasPrefix "x86_64" system; + in + "-include cstdint" + (lib.optionalString isX86 " -msse4.2 -mpclmul"); + + # WASM Toolchain + CC_wasm32_unknown_unknown = "${llvmPkg.clang-unwrapped}/bin/clang"; + AR_wasm32_unknown_unknown = "${llvmPkg.llvm}/bin/llvm-ar"; + CFLAGS_wasm32_unknown_unknown = "-I${clangResourceDir}"; + + # Bindgen & Standard Library Path + LIBCLANG_PATH = "${llvmPkg.libclang.lib}/lib"; + RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; + + BINDGEN_EXTRA_CLANG_ARGS = lib.concatStringsSep " " [ + "-I${clangResourceDir}" + "-I${libcInc}/include" + "-fno-stack-protector" + ]; + + # Use cargo home specific to this nix shell to avoid polluting user's cargo home + CARGO_HOME = ".nix-cargo"; + + PYTHONPATH = "./pytest:./nearcore_pytest:./tee_launcher"; + + }; + + shellHook = '' + export PATH="$CARGO_HOME/bin:$PATH" + mkdir -p "$CARGO_HOME" + + echo "🦀 NEAR Dev Shell Active (Nixpkgs Unstable)" + echo "Toolchain: $(rustc --version)" + ''; + }; + } + ); +} diff --git a/nix/cargo-near.nix b/nix/cargo-near.nix new file mode 100644 index 0000000000..8592046932 --- /dev/null +++ b/nix/cargo-near.nix @@ -0,0 +1,63 @@ +{ + lib, + stdenv, + rustPlatform, + fetchFromGitHub, + pkg-config, + openssl, + udev, + apple-sdk_14, +}: + +rustPlatform.buildRustPackage rec { + pname = "cargo-near"; + version = "0.18.0"; + + src = fetchFromGitHub { + owner = "near"; + repo = "cargo-near"; + rev = "cargo-near-v${version}"; + hash = "sha256-rkqXOfItKO1MmdUFCih6b6g5057iWI6s1JWu/F6r0DY="; + }; + + cargoHash = "sha256-6GoSN+BrM0sw4rqW+6PIPwkTqZsJDyZAHOm78MtOm90="; + + nativeBuildInputs = [ + pkg-config + ]; + + buildInputs = [ + openssl + ] + ++ lib.optionals stdenv.isLinux [ + udev + ] + ++ lib.optionals stdenv.isDarwin [ + apple-sdk_14 + ]; + + env = { + # Prevent the crate from trying to build its own OpenSSL + OPENSSL_NO_VENDOR = 1; + } + // lib.optionalAttrs stdenv.isDarwin { + # Darwin Sonoma / SDK 14 Compatibility + SDKROOT = "${apple-sdk_14}/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"; + MACOSX_DEPLOYMENT_TARGET = "14.0"; + CRATE_CC_NO_DEFAULTS = "1"; + + # Required for crates like wasm-opt-sys that need explicit C++ standard alignment + CMAKE_CXX_STANDARD = "17"; + WASM_OPT_CXX_FLAGS = "-std=c++17 -stdlib=libc++"; + }; + + # skip tests as they require network access + doCheck = false; + + meta = with lib; { + description = "Cargo extension for reproducible builds of NEAR smart contracts"; + homepage = "https://github.com/near/cargo-near"; + platforms = platforms.unix; + mainProgram = "cargo near"; + }; +} diff --git a/nix/near-cli-rs.nix b/nix/near-cli-rs.nix new file mode 100644 index 0000000000..80bc4fc484 --- /dev/null +++ b/nix/near-cli-rs.nix @@ -0,0 +1,51 @@ +{ + lib, + rustPlatform, + fetchFromGitHub, + pkg-config, + openssl, + stdenv, + udev, +}: + +rustPlatform.buildRustPackage rec { + pname = "near-cli-rs"; + version = "0.23.5"; + + src = fetchFromGitHub { + owner = "near"; + repo = "near-cli-rs"; + rev = "v${version}"; + hash = "sha256-2m0DkztczxgzwXcPJ4qGj+ThaTzJsKZSvP8WS4dqH6I="; + }; + + cargoHash = "sha256-i430DhFrhVqnZZ0OmC086I4883vxTjW371dSnqyn71k="; + + # nativeBuildInputs: Tools needed on the host to compile the package + nativeBuildInputs = [ + pkg-config + ]; + + # buildInputs: Libraries the resulting binary will link against + buildInputs = [ + openssl + ] + ++ lib.optionals stdenv.isLinux [ + udev + ]; + + env = { + # Prevent the crate from trying to build its own OpenSSL + OPENSSL_NO_VENDOR = 1; + }; + + # skip tests as they require network access + doCheck = false; + + meta = with lib; { + description = "CLI tool for interacting with the NEAR blockchain. Needed for local development and deployment of smart contracts."; + homepage = "https://github.com/near/near-cli-rs"; + platforms = platforms.unix; + mainProgram = "near"; + }; +} diff --git a/nix/py-arkworks-bls12381-lockfile.lock b/nix/py-arkworks-bls12381-lockfile.lock new file mode 100644 index 0000000000..69e6a2368a --- /dev/null +++ b/nix/py-arkworks-bls12381-lockfile.lock @@ -0,0 +1,584 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "ark-bls12-381" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c775f0d12169cba7aae4caeb547bb6a50781c7449a8aa53793827c9ec4abf488" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", +] + +[[package]] +name = "ark-ec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown", + "itertools", + "num-traits", + "rayon", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest", + "itertools", + "num-bigint", + "num-traits", + "paste", + "rayon", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand", + "rayon", +] + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "crypto-common", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "indoc" +version = "2.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" +dependencies = [ + "rustversion", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "libc" +version = "0.2.180" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "portable-atomic" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "py_arkworks_bls12381" +version = "0.3.8" +dependencies = [ + "ark-bls12-381", + "ark-ec", + "ark-ff", + "ark-serialize", + "hex", + "num-bigint", + "num-traits", + "pyo3", + "rayon", +] + +[[package]] +name = "pyo3" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884" +dependencies = [ + "cfg-if", + "indoc", + "libc", + "memoffset", + "num-bigint", + "once_cell", + "portable-atomic", + "pyo3-build-config", + "pyo3-ffi", + "pyo3-macros", + "unindent", +] + +[[package]] +name = "pyo3-build-config" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38" +dependencies = [ + "once_cell", + "target-lexicon", +] + +[[package]] +name = "pyo3-ffi" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636" +dependencies = [ + "libc", + "pyo3-build-config", +] + +[[package]] +name = "pyo3-macros" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453" +dependencies = [ + "proc-macro2", + "pyo3-macros-backend", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "pyo3-macros-backend" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe" +dependencies = [ + "heck", + "proc-macro2", + "pyo3-build-config", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "quote" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rayon" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "unindent" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "zerocopy" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.114", +] diff --git a/nix/python-env.nix b/nix/python-env.nix new file mode 100644 index 0000000000..c9f1de7f67 --- /dev/null +++ b/nix/python-env.nix @@ -0,0 +1,222 @@ +{ pkgs }: + +let + pythonWithCustom = pkgs.python3.override { + packageOverrides = pyfinal: pyprev: { + + nearcore-pytest = pyfinal.buildPythonPackage { + pname = "nearcore-pytest"; + version = "0.1.0"; + + # Use the project root so that ../../libs/ exists in the sandbox + src = ../.; + + pyproject = true; + nativeBuildInputs = [ pyfinal.setuptools ]; + + # This is the crucial part: + # 1. Move into the directory containing the actual package + # 2. But the 'src' still contains the 'libs' folder at the relative path + postPatch = '' + cd pytest/nearcore_pytest + ''; + + # If setuptools still complains about egg_base, we can force the path + # to be created or pointed to correctly during build. + preBuild = '' + mkdir -p ../../libs/nearcore/pytest/lib + ''; + + doCheck = false; + }; + + # NB! downgrade to python 3.12 if blspy is needed + # + # blspy = pyfinal.buildPythonPackage rec { + # pname = "blspy"; + # version = "2.0.2"; + # pyproject = true; + + # src = pyfinal.fetchPypi { + # inherit pname version; + # hash = "sha256-mxLWhfPBBNP+D682GPa4JCctExuOo4QxkK1nBhhzZ3U="; + # }; + + # relic-src = pkgs.fetchFromGitHub { + # owner = "Chia-Network"; + # repo = "relic"; + # rev = "215c69966cb78b255995f0ee9c86bbbb41c3c42b"; + # hash = "sha256-8Q5S6n2ciDB59H1C735bdk/u9Y+FdwlhZvb0lv2NOCI="; + # }; + + # blst-src = pkgs.fetchFromGitHub { + # owner = "supranational"; + # repo = "blst"; + # rev = "6b837a0921cf41e501faaee1976a4035ae29d893"; + # hash = "sha256-6iNpxaMRy438XoC0wk/c/tInNg1I0VuyGFV9sUFk5sc="; + # }; + + # nativeBuildInputs = [ + # pkgs.cmake + # pkgs.pkg-config + # pyfinal.setuptools + # pyfinal.setuptools-scm + # pyfinal.pybind11 + # ]; + + # buildInputs = [ + # pkgs.libsodium + # pkgs.gmp + # pyfinal.pybind11 + # ]; + + # dontUseCmakeConfigure = true; + + # postPatch = '' + # # 1. Strip all FetchContent to prevent network attempts + # find . -name "CMakeLists.txt" -exec sed -i '/FetchContent_Declare/,/FetchContent_MakeAvailable/d' {} + + + # # 2. Setup Relic (writable copy) + # cp -r ${relic-src} ./relic-src + # chmod -R +w ./relic-src + # sed -i 's/cmake_minimum_required(VERSION [0-9.]*)/cmake_minimum_required(VERSION 3.5)/g' ./relic-src/CMakeLists.txt + + # # 3. Inject dependency paths into main CMakeLists + # sed -i "1i set(relic_SOURCE_DIR \''${CMAKE_CURRENT_SOURCE_DIR}/relic-src)" CMakeLists.txt + # sed -i "2i set(blst_SOURCE_DIR ${blst-src})" CMakeLists.txt + # sed -i "3i set(sodium_FOUND TRUE)" CMakeLists.txt + # sed -i "4i set(Sodium_FOUND TRUE)" CMakeLists.txt + + # # 4. Patch binding subdirectory + # if [ -f python-bindings/CMakeLists.txt ]; then + # sed -i '1i find_package(pybind11 REQUIRED)' python-bindings/CMakeLists.txt + # fi + + # # 5. Hardware & Cryptography configuration (Force flags) + # cat >> CMakeLists.txt < Date: Sun, 11 Jan 2026 00:24:41 +0100 Subject: [PATCH 02/15] include cargo expand --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index db38769d03..7ede53a203 100644 --- a/flake.nix +++ b/flake.nix @@ -66,6 +66,7 @@ # Cargo extensions cargo-binstall + cargo-expand cargo-deny cargo-insta cargo-make From 55eef1bcaf3d602571b18c9c3fc23d6fb2f0fa2d Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Sun, 11 Jan 2026 01:03:49 +0100 Subject: [PATCH 03/15] re-organize tools --- flake.lock | 36 +----- flake.nix | 275 ++++++++++++++++++++++++--------------------- nix/python-env.nix | 8 +- 3 files changed, 154 insertions(+), 165 deletions(-) diff --git a/flake.lock b/flake.lock index 351ef02ad5..ed37e096eb 100644 --- a/flake.lock +++ b/flake.lock @@ -19,8 +19,7 @@ "root": { "inputs": { "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay", - "utils": "utils" + "rust-overlay": "rust-overlay" } }, "rust-overlay": { @@ -42,39 +41,6 @@ "repo": "rust-overlay", "type": "github" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 7ede53a203..825bf3be29 100644 --- a/flake.nix +++ b/flake.nix @@ -5,10 +5,9 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; rust-overlay = { url = "github:oxalica/rust-overlay"; - # Ensures rust-overlay uses the same nixpkgs version as this flake + # ensures the overlay uses the same nixpkgs as the cargo project inputs.nixpkgs.follows = "nixpkgs"; }; - utils.url = "github:numtide/flake-utils"; }; outputs = @@ -16,138 +15,156 @@ self, nixpkgs, rust-overlay, - utils, }: - utils.lib.eachDefaultSystem ( - system: - let - # Use the recommended flake output for the overlay - overlays = [ rust-overlay.overlays.default ]; - pkgs = import nixpkgs { inherit system overlays; }; - - inherit (pkgs) lib; - llvmPkg = pkgs.llvmPackages_19; - - # Load toolchain from file and add necessary components - rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { - extensions = [ - "rust-src" - "rust-analyzer" - "clippy" - "rustfmt" - ]; + let + # 1. Define supported architectures + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + + # 2. Helper to iterate over systems without flake-utils + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + + # 3. Functional helper to get pkgs with overlay applied + pkgsFor = + system: + import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; }; - - pythonEnv = import ./nix/python-env.nix { inherit pkgs; }; - - # Helper variables for Clang/LLVM paths - clangVersion = lib.versions.major llvmPkg.clang-unwrapped.version; - clangResourceDir = "${llvmPkg.clang-unwrapped.lib}/lib/clang/${clangVersion}/include"; - libcInc = lib.getDev pkgs.stdenv.cc.libc; - - # Near tools - cargo-near = pkgs.callPackage ./nix/cargo-near.nix { }; - near-cli-rs = pkgs.callPackage ./nix/near-cli-rs.nix { }; - in - { - devShells.default = pkgs.mkShell { - # strictDeps ensures that build-time tools and run-time libs are correctly separated - strictDeps = true; - - # Developer Tools - nativeBuildInputs = with pkgs; [ - pkg-config - llvmPkg.clang - llvmPkg.libclang - - # Rust - rustToolchain - rustPlatform.bindgenHook - - # Cargo extensions - cargo-binstall - cargo-expand - cargo-deny - cargo-insta - cargo-make - cargo-nextest - cargo-shear - cargo-sort - - # wasm-opt - binaryen - - # Near CLI and SDK - near-cli-rs - cargo-near - - # python - pythonEnv - - # Various utilities - git - zizmor - ]; - - # Dynamic libraries required for build - buildInputs = - with pkgs; - [ - openssl - zlib - libiconv - snappy - lz4 - zstd - bzip2 - ] - ++ lib.optionals stdenv.isLinux [ - udev - dbus - ] - ++ lib.optionals stdenv.isDarwin [ - pkgs.apple-sdk + in + { + devShells = forAllSystems ( + system: + let + pkgs = pkgsFor system; + inherit (pkgs) lib; + llvmPkg = pkgs.llvmPackages_19; + + # Rust Toolchain setup + rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { + extensions = [ + "rust-src" + "rust-analyzer" + "clippy" + "rustfmt" ]; + }; - env = { - # Needed for neard's librockdb build - # Apply x86-specific flags ONLY on x86_64 machines - CXXFLAGS = - let - isX86 = lib.strings.hasPrefix "x86_64" system; - in - "-include cstdint" + (lib.optionalString isX86 " -msse4.2 -mpclmul"); - - # WASM Toolchain - CC_wasm32_unknown_unknown = "${llvmPkg.clang-unwrapped}/bin/clang"; - AR_wasm32_unknown_unknown = "${llvmPkg.llvm}/bin/llvm-ar"; - CFLAGS_wasm32_unknown_unknown = "-I${clangResourceDir}"; - - # Bindgen & Standard Library Path - LIBCLANG_PATH = "${llvmPkg.libclang.lib}/lib"; - RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; - - BINDGEN_EXTRA_CLANG_ARGS = lib.concatStringsSep " " [ - "-I${clangResourceDir}" - "-I${libcInc}/include" - "-fno-stack-protector" + pythonEnv = import ./nix/python-env.nix { inherit pkgs; }; + + # LLVM/Clang Helpers + clangVersion = lib.versions.major llvmPkg.clang-unwrapped.version; + clangResourceDir = "${llvmPkg.clang-unwrapped.lib}/lib/clang/${clangVersion}/include"; + libcInc = lib.getDev pkgs.stdenv.cc.libc; + + # Custom NEAR local packages + cargo-near = pkgs.callPackage ./nix/cargo-near.nix { }; + near-cli-rs = pkgs.callPackage ./nix/near-cli-rs.nix { }; + in + { + default = pkgs.mkShell { + strictDeps = true; + + nativeBuildInputs = with pkgs; [ + # Docker Tools, note docker daemon must be running separately + docker + docker-compose + + # LLVM/Clang Tools + pkg-config + llvmPkg.clang + llvmPkg.libclang + + # Rust Toolchain + rustToolchain + rustPlatform.bindgenHook + + # Cargo & Build tools + cargo-binstall + cargo-deny + cargo-insta + cargo-make + cargo-nextest + cargo-shear + cargo-sort + + # wasm-opt + binaryen + + # NEAR CLI Tools + near-cli-rs + cargo-near + + # Python environment for pytests + pythonEnv + + # Misc Utilities + git + zizmor ]; - # Use cargo home specific to this nix shell to avoid polluting user's cargo home - CARGO_HOME = ".nix-cargo"; - - PYTHONPATH = "./pytest:./nearcore_pytest:./tee_launcher"; - + buildInputs = + with pkgs; + [ + openssl + zlib + libiconv + snappy + lz4 + zstd + bzip2 + ] + ++ lib.optionals stdenv.isLinux [ + udev + dbus + ] + ++ lib.optionals stdenv.isDarwin [ + pkgs.apple-sdk + ]; + + env = { + # needed for neard's rocksdb build to avoid unsupported CPU features + CXXFLAGS = + let + isX86 = lib.strings.hasPrefix "x86_64" system; + in + "-include cstdint" + (lib.optionalString isX86 " -msse4.2 -mpclmul"); + + # WASM Toolchain + CC_wasm32_unknown_unknown = "${llvmPkg.clang-unwrapped}/bin/clang"; + AR_wasm32_unknown_unknown = "${llvmPkg.llvm}/bin/llvm-ar"; + CFLAGS_wasm32_unknown_unknown = "-I${clangResourceDir}"; + + # Bindgen & Paths + LIBCLANG_PATH = "${llvmPkg.libclang.lib}/lib"; + RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; + + BINDGEN_EXTRA_CLANG_ARGS = lib.concatStringsSep " " [ + "-I${clangResourceDir}" + "-I${libcInc}/include" + "-fno-stack-protector" + ]; + + PYTHONPATH = "./pytest:./nearcore_pytest:./tee_launcher"; + + # Prevent Cargo from trying to use the system rustup + RUSTUP_TOOLCHAIN = ""; + CARGO_HOME = ".nix-cargo"; + }; + + shellHook = '' + mkdir -p .nix-cargo + export PATH="$PWD/.nix-cargo/bin:$PATH" + + printf "\e[32m🦀 NEAR Dev Shell Active\e[0m\n" + + # echo "🦀 NEAR Dev Shell Active | $(rustc --version)" + ''; }; - - shellHook = '' - export PATH="$CARGO_HOME/bin:$PATH" - mkdir -p "$CARGO_HOME" - - echo "🦀 NEAR Dev Shell Active (Nixpkgs Unstable)" - echo "Toolchain: $(rustc --version)" - ''; - }; - } - ); + } + ); + }; } diff --git a/nix/python-env.nix b/nix/python-env.nix index c9f1de7f67..dc9b91a15a 100644 --- a/nix/python-env.nix +++ b/nix/python-env.nix @@ -185,11 +185,17 @@ let in pythonWithCustom.withPackages ( ps: with ps; [ + # key ring required by NEAR cli for storing credentials + keyring + + # linter + ruff + + # pytest deps pytest pytest-rerunfailures gitpython ruamel-yaml - ruff pygithub base58 cachetools From 323faf2b4998e2d8d346c80a4fa79493f61b1611 Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Sun, 11 Jan 2026 16:22:47 +0100 Subject: [PATCH 04/15] remove hardening to fix jmalloc in integration tests --- flake.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 825bf3be29..07f2dd6e07 100644 --- a/flake.nix +++ b/flake.nix @@ -129,7 +129,7 @@ # needed for neard's rocksdb build to avoid unsupported CPU features CXXFLAGS = let - isX86 = lib.strings.hasPrefix "x86_64" system; + isX86 = pkgs.stdenv.hostPlatform.isx86_64; in "-include cstdint" + (lib.optionalString isX86 " -msse4.2 -mpclmul"); @@ -155,6 +155,10 @@ CARGO_HOME = ".nix-cargo"; }; + # Remove the hardening added by nix to fix jmalloc compilation error. + # More info: https://github.com/tikv/jemallocator/issues/108 + hardeningDisable = [ "fortify" ]; + shellHook = '' mkdir -p .nix-cargo export PATH="$PWD/.nix-cargo/bin:$PATH" From 80a7007d3cd1dcf1d1b29d40815fd61bbe9b5cb2 Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Sun, 11 Jan 2026 16:37:06 +0100 Subject: [PATCH 05/15] Extend the readme --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 71651b55ec..d9a03c4ca1 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,21 @@ This repository contains the code for the Near MPC node. It is a rewrite of [Nea - **Nearcore Node**: This repository depends on the nearcore node, included as a submodule in the `/libs` directory. - **Other Dependencies**: All other dependencies are handled by Cargo. +## Development Environment (Nix) + +This repository includes a [flake.nix](flake.nix) file that provides a reproducible development environment using Nix. This environment pre-configures the Rust toolchain, LLVM/Clang tools, NEAR CLI tools, and all necessary system dependencies. +Prerequisites + - **Nix**: Install Nix with [Flakes enabled](https://nixos.wiki/wiki/Flakes) + - **Docker**: While tools are provided in the shell, the Docker daemon must be running separately on your host system. Docker is required for reproducible builds of the MPC contract. + +### Entering the Shell +To activate the development environment, run the following command in the project root: +```shell +nix develop +``` + +Once you enter the shell, your workspace is immediately ready for development. + ## How it works There are two main parts of the binary: NEAR indexer and MPC signing: From e217f60b8f5bc498feb34f881dd1858e31259679 Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Tue, 13 Jan 2026 09:03:27 +0100 Subject: [PATCH 06/15] move ruff + keyring, and dev build for macos --- flake.nix | 32 ++++++++++++++++++++++++++++---- nix/python-env.nix | 6 ------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 07f2dd6e07..742f5042e2 100644 --- a/flake.nix +++ b/flake.nix @@ -69,7 +69,7 @@ strictDeps = true; nativeBuildInputs = with pkgs; [ - # Docker Tools, note docker daemon must be running separately + # Docker Tools. NB! docker daemon must be running separately docker docker-compose @@ -95,11 +95,13 @@ binaryen # NEAR CLI Tools + python3Packages.keyring near-cli-rs cargo-near - # Python environment for pytests - pythonEnv + # python + ruff + pythonEnv # Python environment for pytests # Misc Utilities git @@ -153,11 +155,33 @@ # Prevent Cargo from trying to use the system rustup RUSTUP_TOOLCHAIN = ""; CARGO_HOME = ".nix-cargo"; + + ## BEGIN MACOS + # Force Cargo build scripts + autotools to use Nix wrappers (NOT Homebrew clang) + CC = "${pkgs.stdenv.cc}/bin/cc"; + CXX = "${pkgs.stdenv.cc}/bin/c++"; + + # cc crate looks for these first on macOS + CC_aarch64_apple_darwin = "${pkgs.stdenv.cc}/bin/cc"; + CXX_aarch64_apple_darwin = "${pkgs.stdenv.cc}/bin/c++"; + + AR = "${pkgs.stdenv.cc.bintools}/bin/ar"; + RANLIB = "${pkgs.stdenv.cc.bintools}/bin/ranlib"; + ## END MACOS }; # Remove the hardening added by nix to fix jmalloc compilation error. # More info: https://github.com/tikv/jemallocator/issues/108 - hardeningDisable = [ "fortify" ]; + hardeningDisable = [ + "fortify" + ] + ++ lib.optionals pkgs.stdenv.isDarwin [ + "fortify" + "stackprotector" + "strictoverflow" + "format" + "zerocallusedregs" + ]; shellHook = '' mkdir -p .nix-cargo diff --git a/nix/python-env.nix b/nix/python-env.nix index dc9b91a15a..282523aa5e 100644 --- a/nix/python-env.nix +++ b/nix/python-env.nix @@ -185,12 +185,6 @@ let in pythonWithCustom.withPackages ( ps: with ps; [ - # key ring required by NEAR cli for storing credentials - keyring - - # linter - ruff - # pytest deps pytest pytest-rerunfailures From 06bbcde518254f58b18db3f56cc34ebff66954f4 Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Tue, 13 Jan 2026 09:05:46 +0100 Subject: [PATCH 07/15] clean up env --- flake.nix | 86 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/flake.nix b/flake.nix index 742f5042e2..98f4cfe35f 100644 --- a/flake.nix +++ b/flake.nix @@ -127,48 +127,50 @@ pkgs.apple-sdk ]; - env = { - # needed for neard's rocksdb build to avoid unsupported CPU features - CXXFLAGS = - let - isX86 = pkgs.stdenv.hostPlatform.isx86_64; - in - "-include cstdint" + (lib.optionalString isX86 " -msse4.2 -mpclmul"); - - # WASM Toolchain - CC_wasm32_unknown_unknown = "${llvmPkg.clang-unwrapped}/bin/clang"; - AR_wasm32_unknown_unknown = "${llvmPkg.llvm}/bin/llvm-ar"; - CFLAGS_wasm32_unknown_unknown = "-I${clangResourceDir}"; - - # Bindgen & Paths - LIBCLANG_PATH = "${llvmPkg.libclang.lib}/lib"; - RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; - - BINDGEN_EXTRA_CLANG_ARGS = lib.concatStringsSep " " [ - "-I${clangResourceDir}" - "-I${libcInc}/include" - "-fno-stack-protector" - ]; - - PYTHONPATH = "./pytest:./nearcore_pytest:./tee_launcher"; - - # Prevent Cargo from trying to use the system rustup - RUSTUP_TOOLCHAIN = ""; - CARGO_HOME = ".nix-cargo"; - - ## BEGIN MACOS - # Force Cargo build scripts + autotools to use Nix wrappers (NOT Homebrew clang) - CC = "${pkgs.stdenv.cc}/bin/cc"; - CXX = "${pkgs.stdenv.cc}/bin/c++"; - - # cc crate looks for these first on macOS - CC_aarch64_apple_darwin = "${pkgs.stdenv.cc}/bin/cc"; - CXX_aarch64_apple_darwin = "${pkgs.stdenv.cc}/bin/c++"; - - AR = "${pkgs.stdenv.cc.bintools}/bin/ar"; - RANLIB = "${pkgs.stdenv.cc.bintools}/bin/ranlib"; - ## END MACOS - }; + env = + let + isX86 = pkgs.stdenv.hostPlatform.isx86_64; + + commonEnv = { + # needed for neard's rocksdb build to avoid unsupported CPU features + CXXFLAGS = "-include cstdint" + (lib.optionalString isX86 " -msse4.2 -mpclmul"); + + # WASM Toolchain + CC_wasm32_unknown_unknown = "${llvmPkg.clang-unwrapped}/bin/clang"; + AR_wasm32_unknown_unknown = "${llvmPkg.llvm}/bin/llvm-ar"; + CFLAGS_wasm32_unknown_unknown = "-I${clangResourceDir}"; + + # Bindgen & Paths + LIBCLANG_PATH = "${llvmPkg.libclang.lib}/lib"; + RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; + + BINDGEN_EXTRA_CLANG_ARGS = lib.concatStringsSep " " [ + "-I${clangResourceDir}" + "-I${libcInc}/include" + "-fno-stack-protector" + ]; + + PYTHONPATH = "./pytest:./nearcore_pytest:./tee_launcher"; + + # Prevent Cargo from trying to use the system rustup + RUSTUP_TOOLCHAIN = ""; + CARGO_HOME = ".nix-cargo"; + }; + + # Force Cargo build scripts + autotools to use Nix wrappers (NOT host clang) + macosEnv = lib.optionalAttrs pkgs.stdenv.isDarwin { + CC = "${pkgs.stdenv.cc}/bin/cc"; + CXX = "${pkgs.stdenv.cc}/bin/c++"; + + # cc crate looks for these first on macOS + CC_aarch64_apple_darwin = "${pkgs.stdenv.cc}/bin/cc"; + CXX_aarch64_apple_darwin = "${pkgs.stdenv.cc}/bin/c++"; + + AR = "${pkgs.stdenv.cc.bintools}/bin/ar"; + RANLIB = "${pkgs.stdenv.cc.bintools}/bin/ranlib"; + }; + in + commonEnv // macosEnv; # Remove the hardening added by nix to fix jmalloc compilation error. # More info: https://github.com/tikv/jemallocator/issues/108 From b2c04602b8ee382f1b62d2ededdf2c0d5433fe82 Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Tue, 13 Jan 2026 09:13:15 +0100 Subject: [PATCH 08/15] further cleanup --- flake.nix | 280 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 147 insertions(+), 133 deletions(-) diff --git a/flake.nix b/flake.nix index 98f4cfe35f..4bceb68965 100644 --- a/flake.nix +++ b/flake.nix @@ -3,9 +3,9 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { url = "github:oxalica/rust-overlay"; - # ensures the overlay uses the same nixpkgs as the cargo project inputs.nixpkgs.follows = "nixpkgs"; }; }; @@ -17,33 +17,40 @@ rust-overlay, }: let - # 1. Define supported architectures - supportedSystems = [ + lib = nixpkgs.lib; + + systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; - # 2. Helper to iterate over systems without flake-utils - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - - # 3. Functional helper to get pkgs with overlay applied pkgsFor = system: import nixpkgs { inherit system; overlays = [ rust-overlay.overlays.default ]; }; + + forAllSystems = f: lib.genAttrs systems (system: f (pkgsFor system)); + + # Helper: compute clang resource include dir for bindgen/wasm. + clangResourceInclude = + llvmPkgs: + let + clangVersion = lib.versions.major llvmPkgs.clang-unwrapped.version; + in + "${llvmPkgs.clang-unwrapped.lib}/lib/clang/${clangVersion}/include"; + in { devShells = forAllSystems ( - system: + pkgs: let - pkgs = pkgsFor system; - inherit (pkgs) lib; - llvmPkg = pkgs.llvmPackages_19; + inherit (pkgs) stdenv; + + llvmPkgs = pkgs.llvmPackages_19; - # Rust Toolchain setup rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { extensions = [ "rust-src" @@ -55,143 +62,150 @@ pythonEnv = import ./nix/python-env.nix { inherit pkgs; }; - # LLVM/Clang Helpers - clangVersion = lib.versions.major llvmPkg.clang-unwrapped.version; - clangResourceDir = "${llvmPkg.clang-unwrapped.lib}/lib/clang/${clangVersion}/include"; - libcInc = lib.getDev pkgs.stdenv.cc.libc; - - # Custom NEAR local packages + # Local NEAR tooling cargo-near = pkgs.callPackage ./nix/cargo-near.nix { }; near-cli-rs = pkgs.callPackage ./nix/near-cli-rs.nix { }; + + libcDev = lib.getDev stdenv.cc.libc; + + isX86 = stdenv.hostPlatform.isx86_64; + + envCommon = { + # needed for neard's rocksdb build to avoid unsupported CPU features + CXXFLAGS = "-include cstdint" + lib.optionalString isX86 " -msse4.2 -mpclmul"; + + # WASM Toolchain + CC_wasm32_unknown_unknown = "${llvmPkgs.clang-unwrapped}/bin/clang"; + AR_wasm32_unknown_unknown = "${llvmPkgs.llvm}/bin/llvm-ar"; + CFLAGS_wasm32_unknown_unknown = "-I${clangResourceInclude llvmPkgs}"; + + # Bindgen & Paths + LIBCLANG_PATH = "${llvmPkgs.libclang.lib}/lib"; + RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; + + BINDGEN_EXTRA_CLANG_ARGS = lib.concatStringsSep " " [ + "-I${clangResourceInclude llvmPkgs}" + "-I${libcDev}/include" + "-fno-stack-protector" + ]; + + PYTHONPATH = "./pytest:./nearcore_pytest:./tee_launcher"; + + # Prevent Cargo from trying to use the system rustup + RUSTUP_TOOLCHAIN = ""; + CARGO_HOME = ".nix-cargo"; + }; + + envDarwin = lib.optionalAttrs stdenv.isDarwin { + # Force build scripts to use Nix wrappers (not host clang) + CC = "${stdenv.cc}/bin/cc"; + CXX = "${stdenv.cc}/bin/c++"; + + # cc crate looks for these first on macOS + CC_aarch64_apple_darwin = "${stdenv.cc}/bin/cc"; + CXX_aarch64_apple_darwin = "${stdenv.cc}/bin/c++"; + + AR = "${stdenv.cc.bintools}/bin/ar"; + RANLIB = "${stdenv.cc.bintools}/bin/ranlib"; + }; + + # Tool groups (makes it much easier to edit later) + dockerTools = with pkgs; [ + docker + docker-compose + ]; + + llvmTools = [ + pkgs.pkg-config + llvmPkgs.clang + llvmPkgs.libclang + ]; + + rustTools = with pkgs; [ + rustToolchain + rustPlatform.bindgenHook + ]; + + cargoTools = with pkgs; [ + cargo-binstall + cargo-deny + cargo-insta + cargo-make + cargo-nextest + cargo-shear + cargo-sort + ]; + + nearTools = with pkgs; [ + python3Packages.keyring + near-cli-rs + cargo-near + ]; + + pythonTools = with pkgs; [ + ruff + pythonEnv + ]; + + miscTools = with pkgs; [ + git + zizmor + binaryen + ]; + + buildLibs = + with pkgs; + [ + openssl + zlib + libiconv + snappy + lz4 + zstd + bzip2 + ] + ++ lib.optionals stdenv.isLinux [ + udev + dbus + ]; + + hardening = [ + "fortify" + ] + ++ lib.optionals stdenv.isDarwin [ + "stackprotector" + "strictoverflow" + "format" + "zerocallusedregs" + ]; + in { default = pkgs.mkShell { strictDeps = true; - nativeBuildInputs = with pkgs; [ - # Docker Tools. NB! docker daemon must be running separately - docker - docker-compose - - # LLVM/Clang Tools - pkg-config - llvmPkg.clang - llvmPkg.libclang - - # Rust Toolchain - rustToolchain - rustPlatform.bindgenHook - - # Cargo & Build tools - cargo-binstall - cargo-deny - cargo-insta - cargo-make - cargo-nextest - cargo-shear - cargo-sort - - # wasm-opt - binaryen - - # NEAR CLI Tools - python3Packages.keyring - near-cli-rs - cargo-near - - # python - ruff - pythonEnv # Python environment for pytests - - # Misc Utilities - git - zizmor - ]; + # Prefer `packages` for devShells: clearer and avoids + # having to think about nativeBuildInputs vs buildInputs in a shell. + packages = + dockerTools + ++ llvmTools + ++ rustTools + ++ cargoTools + ++ nearTools + ++ pythonTools + ++ miscTools + ++ buildLibs; - buildInputs = - with pkgs; - [ - openssl - zlib - libiconv - snappy - lz4 - zstd - bzip2 - ] - ++ lib.optionals stdenv.isLinux [ - udev - dbus - ] - ++ lib.optionals stdenv.isDarwin [ - pkgs.apple-sdk - ]; - - env = - let - isX86 = pkgs.stdenv.hostPlatform.isx86_64; - - commonEnv = { - # needed for neard's rocksdb build to avoid unsupported CPU features - CXXFLAGS = "-include cstdint" + (lib.optionalString isX86 " -msse4.2 -mpclmul"); - - # WASM Toolchain - CC_wasm32_unknown_unknown = "${llvmPkg.clang-unwrapped}/bin/clang"; - AR_wasm32_unknown_unknown = "${llvmPkg.llvm}/bin/llvm-ar"; - CFLAGS_wasm32_unknown_unknown = "-I${clangResourceDir}"; - - # Bindgen & Paths - LIBCLANG_PATH = "${llvmPkg.libclang.lib}/lib"; - RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; - - BINDGEN_EXTRA_CLANG_ARGS = lib.concatStringsSep " " [ - "-I${clangResourceDir}" - "-I${libcInc}/include" - "-fno-stack-protector" - ]; - - PYTHONPATH = "./pytest:./nearcore_pytest:./tee_launcher"; - - # Prevent Cargo from trying to use the system rustup - RUSTUP_TOOLCHAIN = ""; - CARGO_HOME = ".nix-cargo"; - }; - - # Force Cargo build scripts + autotools to use Nix wrappers (NOT host clang) - macosEnv = lib.optionalAttrs pkgs.stdenv.isDarwin { - CC = "${pkgs.stdenv.cc}/bin/cc"; - CXX = "${pkgs.stdenv.cc}/bin/c++"; - - # cc crate looks for these first on macOS - CC_aarch64_apple_darwin = "${pkgs.stdenv.cc}/bin/cc"; - CXX_aarch64_apple_darwin = "${pkgs.stdenv.cc}/bin/c++"; - - AR = "${pkgs.stdenv.cc.bintools}/bin/ar"; - RANLIB = "${pkgs.stdenv.cc.bintools}/bin/ranlib"; - }; - in - commonEnv // macosEnv; + env = envCommon // envDarwin; # Remove the hardening added by nix to fix jmalloc compilation error. # More info: https://github.com/tikv/jemallocator/issues/108 - hardeningDisable = [ - "fortify" - ] - ++ lib.optionals pkgs.stdenv.isDarwin [ - "fortify" - "stackprotector" - "strictoverflow" - "format" - "zerocallusedregs" - ]; + hardeningDisable = hardening; shellHook = '' mkdir -p .nix-cargo export PATH="$PWD/.nix-cargo/bin:$PATH" - printf "\e[32m🦀 NEAR Dev Shell Active\e[0m\n" - - # echo "🦀 NEAR Dev Shell Active | $(rustc --version)" ''; }; } From ea323dd23ee1a8f12f81fdee54c22b7b65e7aaab Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Tue, 13 Jan 2026 09:14:29 +0100 Subject: [PATCH 09/15] disable python for nw --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 4bceb68965..8827023bbf 100644 --- a/flake.nix +++ b/flake.nix @@ -60,7 +60,7 @@ ]; }; - pythonEnv = import ./nix/python-env.nix { inherit pkgs; }; + # pythonEnv = import ./nix/python-env.nix { inherit pkgs; }; # Local NEAR tooling cargo-near = pkgs.callPackage ./nix/cargo-near.nix { }; @@ -144,7 +144,7 @@ pythonTools = with pkgs; [ ruff - pythonEnv + # pythonEnv ]; miscTools = with pkgs; [ From ecb8a75527cb13025222a695b1096138c67f0ad2 Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Tue, 13 Jan 2026 09:18:22 +0100 Subject: [PATCH 10/15] remove obvious comment --- flake.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/flake.nix b/flake.nix index 8827023bbf..fa5286c84b 100644 --- a/flake.nix +++ b/flake.nix @@ -109,7 +109,6 @@ RANLIB = "${stdenv.cc.bintools}/bin/ranlib"; }; - # Tool groups (makes it much easier to edit later) dockerTools = with pkgs; [ docker docker-compose @@ -184,8 +183,6 @@ default = pkgs.mkShell { strictDeps = true; - # Prefer `packages` for devShells: clearer and avoids - # having to think about nativeBuildInputs vs buildInputs in a shell. packages = dockerTools ++ llvmTools From dbbd94a7f9c6fb18322ba508bcf80360e668d983 Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Tue, 13 Jan 2026 09:19:59 +0100 Subject: [PATCH 11/15] remove comment --- nix/python-env.nix | 5 ----- 1 file changed, 5 deletions(-) diff --git a/nix/python-env.nix b/nix/python-env.nix index 282523aa5e..098ba1767b 100644 --- a/nix/python-env.nix +++ b/nix/python-env.nix @@ -14,15 +14,10 @@ let pyproject = true; nativeBuildInputs = [ pyfinal.setuptools ]; - # This is the crucial part: - # 1. Move into the directory containing the actual package - # 2. But the 'src' still contains the 'libs' folder at the relative path postPatch = '' cd pytest/nearcore_pytest ''; - # If setuptools still complains about egg_base, we can force the path - # to be created or pointed to correctly during build. preBuild = '' mkdir -p ../../libs/nearcore/pytest/lib ''; From f6018765f87a21c4ee17057428b709b978ed20e8 Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Tue, 13 Jan 2026 09:35:25 +0100 Subject: [PATCH 12/15] include nix download link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9a03c4ca1..5dc48e303e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This repository contains the code for the Near MPC node. It is a rewrite of [Nea This repository includes a [flake.nix](flake.nix) file that provides a reproducible development environment using Nix. This environment pre-configures the Rust toolchain, LLVM/Clang tools, NEAR CLI tools, and all necessary system dependencies. Prerequisites - - **Nix**: Install Nix with [Flakes enabled](https://nixos.wiki/wiki/Flakes) + - **Nix**: [Install Nix](https://nixos.org/download/) with [Flakes enabled](https://nixos.wiki/wiki/Flakes) - **Docker**: While tools are provided in the shell, the Docker daemon must be running separately on your host system. Docker is required for reproducible builds of the MPC contract. ### Entering the Shell From 6e35f7e4ee3356ba2d966c70d56d9ff44bf45f29 Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Wed, 14 Jan 2026 09:19:45 +0100 Subject: [PATCH 13/15] remove python related packages for now --- flake.nix | 16 +- nix/py-arkworks-bls12381-lockfile.lock | 584 ------------------------- nix/python-env.nix | 217 --------- 3 files changed, 1 insertion(+), 816 deletions(-) delete mode 100644 nix/py-arkworks-bls12381-lockfile.lock delete mode 100644 nix/python-env.nix diff --git a/flake.nix b/flake.nix index fa5286c84b..a9b77d9b2c 100644 --- a/flake.nix +++ b/flake.nix @@ -60,8 +60,6 @@ ]; }; - # pythonEnv = import ./nix/python-env.nix { inherit pkgs; }; - # Local NEAR tooling cargo-near = pkgs.callPackage ./nix/cargo-near.nix { }; near-cli-rs = pkgs.callPackage ./nix/near-cli-rs.nix { }; @@ -141,11 +139,6 @@ cargo-near ]; - pythonTools = with pkgs; [ - ruff - # pythonEnv - ]; - miscTools = with pkgs; [ git zizmor @@ -184,14 +177,7 @@ strictDeps = true; packages = - dockerTools - ++ llvmTools - ++ rustTools - ++ cargoTools - ++ nearTools - ++ pythonTools - ++ miscTools - ++ buildLibs; + dockerTools ++ llvmTools ++ rustTools ++ cargoTools ++ nearTools ++ miscTools ++ buildLibs; env = envCommon // envDarwin; diff --git a/nix/py-arkworks-bls12381-lockfile.lock b/nix/py-arkworks-bls12381-lockfile.lock deleted file mode 100644 index 69e6a2368a..0000000000 --- a/nix/py-arkworks-bls12381-lockfile.lock +++ /dev/null @@ -1,584 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "ark-bls12-381" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c775f0d12169cba7aae4caeb547bb6a50781c7449a8aa53793827c9ec4abf488" -dependencies = [ - "ark-ec", - "ark-ff", - "ark-serialize", - "ark-std", -] - -[[package]] -name = "ark-ec" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" -dependencies = [ - "ark-ff", - "ark-poly", - "ark-serialize", - "ark-std", - "derivative", - "hashbrown", - "itertools", - "num-traits", - "rayon", - "zeroize", -] - -[[package]] -name = "ark-ff" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" -dependencies = [ - "ark-ff-asm", - "ark-ff-macros", - "ark-serialize", - "ark-std", - "derivative", - "digest", - "itertools", - "num-bigint", - "num-traits", - "paste", - "rayon", - "rustc_version", - "zeroize", -] - -[[package]] -name = "ark-ff-asm" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" -dependencies = [ - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ark-ff-macros" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" -dependencies = [ - "num-bigint", - "num-traits", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ark-poly" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" -dependencies = [ - "ark-ff", - "ark-serialize", - "ark-std", - "derivative", - "hashbrown", -] - -[[package]] -name = "ark-serialize" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" -dependencies = [ - "ark-serialize-derive", - "ark-std", - "digest", - "num-bigint", -] - -[[package]] -name = "ark-serialize-derive" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ark-std" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" -dependencies = [ - "num-traits", - "rand", - "rayon", -] - -[[package]] -name = "autocfg" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" - -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - -[[package]] -name = "crossbeam-deque" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" - -[[package]] -name = "crypto-common" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "crypto-common", -] - -[[package]] -name = "either" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "indoc" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" -dependencies = [ - "rustversion", -] - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - -[[package]] -name = "libc" -version = "0.2.180" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" - -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - -[[package]] -name = "once_cell" -version = "1.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" - -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - -[[package]] -name = "portable-atomic" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" - -[[package]] -name = "ppv-lite86" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.105" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "py_arkworks_bls12381" -version = "0.3.8" -dependencies = [ - "ark-bls12-381", - "ark-ec", - "ark-ff", - "ark-serialize", - "hex", - "num-bigint", - "num-traits", - "pyo3", - "rayon", -] - -[[package]] -name = "pyo3" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884" -dependencies = [ - "cfg-if", - "indoc", - "libc", - "memoffset", - "num-bigint", - "once_cell", - "portable-atomic", - "pyo3-build-config", - "pyo3-ffi", - "pyo3-macros", - "unindent", -] - -[[package]] -name = "pyo3-build-config" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38" -dependencies = [ - "once_cell", - "target-lexicon", -] - -[[package]] -name = "pyo3-ffi" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636" -dependencies = [ - "libc", - "pyo3-build-config", -] - -[[package]] -name = "pyo3-macros" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453" -dependencies = [ - "proc-macro2", - "pyo3-macros-backend", - "quote", - "syn 2.0.114", -] - -[[package]] -name = "pyo3-macros-backend" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe" -dependencies = [ - "heck", - "proc-macro2", - "pyo3-build-config", - "quote", - "syn 2.0.114", -] - -[[package]] -name = "quote" -version = "1.0.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" - -[[package]] -name = "rayon" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - -[[package]] -name = "rustversion" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" - -[[package]] -name = "semver" -version = "1.0.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.114" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "target-lexicon" -version = "0.12.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" - -[[package]] -name = "typenum" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" - -[[package]] -name = "unicode-ident" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" - -[[package]] -name = "unindent" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "zerocopy" -version = "0.8.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.114", -] - -[[package]] -name = "zeroize" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.114", -] diff --git a/nix/python-env.nix b/nix/python-env.nix deleted file mode 100644 index 098ba1767b..0000000000 --- a/nix/python-env.nix +++ /dev/null @@ -1,217 +0,0 @@ -{ pkgs }: - -let - pythonWithCustom = pkgs.python3.override { - packageOverrides = pyfinal: pyprev: { - - nearcore-pytest = pyfinal.buildPythonPackage { - pname = "nearcore-pytest"; - version = "0.1.0"; - - # Use the project root so that ../../libs/ exists in the sandbox - src = ../.; - - pyproject = true; - nativeBuildInputs = [ pyfinal.setuptools ]; - - postPatch = '' - cd pytest/nearcore_pytest - ''; - - preBuild = '' - mkdir -p ../../libs/nearcore/pytest/lib - ''; - - doCheck = false; - }; - - # NB! downgrade to python 3.12 if blspy is needed - # - # blspy = pyfinal.buildPythonPackage rec { - # pname = "blspy"; - # version = "2.0.2"; - # pyproject = true; - - # src = pyfinal.fetchPypi { - # inherit pname version; - # hash = "sha256-mxLWhfPBBNP+D682GPa4JCctExuOo4QxkK1nBhhzZ3U="; - # }; - - # relic-src = pkgs.fetchFromGitHub { - # owner = "Chia-Network"; - # repo = "relic"; - # rev = "215c69966cb78b255995f0ee9c86bbbb41c3c42b"; - # hash = "sha256-8Q5S6n2ciDB59H1C735bdk/u9Y+FdwlhZvb0lv2NOCI="; - # }; - - # blst-src = pkgs.fetchFromGitHub { - # owner = "supranational"; - # repo = "blst"; - # rev = "6b837a0921cf41e501faaee1976a4035ae29d893"; - # hash = "sha256-6iNpxaMRy438XoC0wk/c/tInNg1I0VuyGFV9sUFk5sc="; - # }; - - # nativeBuildInputs = [ - # pkgs.cmake - # pkgs.pkg-config - # pyfinal.setuptools - # pyfinal.setuptools-scm - # pyfinal.pybind11 - # ]; - - # buildInputs = [ - # pkgs.libsodium - # pkgs.gmp - # pyfinal.pybind11 - # ]; - - # dontUseCmakeConfigure = true; - - # postPatch = '' - # # 1. Strip all FetchContent to prevent network attempts - # find . -name "CMakeLists.txt" -exec sed -i '/FetchContent_Declare/,/FetchContent_MakeAvailable/d' {} + - - # # 2. Setup Relic (writable copy) - # cp -r ${relic-src} ./relic-src - # chmod -R +w ./relic-src - # sed -i 's/cmake_minimum_required(VERSION [0-9.]*)/cmake_minimum_required(VERSION 3.5)/g' ./relic-src/CMakeLists.txt - - # # 3. Inject dependency paths into main CMakeLists - # sed -i "1i set(relic_SOURCE_DIR \''${CMAKE_CURRENT_SOURCE_DIR}/relic-src)" CMakeLists.txt - # sed -i "2i set(blst_SOURCE_DIR ${blst-src})" CMakeLists.txt - # sed -i "3i set(sodium_FOUND TRUE)" CMakeLists.txt - # sed -i "4i set(Sodium_FOUND TRUE)" CMakeLists.txt - - # # 4. Patch binding subdirectory - # if [ -f python-bindings/CMakeLists.txt ]; then - # sed -i '1i find_package(pybind11 REQUIRED)' python-bindings/CMakeLists.txt - # fi - - # # 5. Hardware & Cryptography configuration (Force flags) - # cat >> CMakeLists.txt < Date: Wed, 14 Jan 2026 09:36:00 +0100 Subject: [PATCH 14/15] Use CI version of cargo shear --- flake.nix | 3 +++ nix/cargo-shear.nix | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 nix/cargo-shear.nix diff --git a/flake.nix b/flake.nix index a9b77d9b2c..dbec384f7d 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,9 @@ cargo-near = pkgs.callPackage ./nix/cargo-near.nix { }; near-cli-rs = pkgs.callPackage ./nix/near-cli-rs.nix { }; + # Pinned to CI version + cargo-shear = pkgs.callPackage ./nix/cargo-shear.nix { }; + libcDev = lib.getDev stdenv.cc.libc; isX86 = stdenv.hostPlatform.isx86_64; diff --git a/nix/cargo-shear.nix b/nix/cargo-shear.nix new file mode 100644 index 0000000000..7bfbd6ea9b --- /dev/null +++ b/nix/cargo-shear.nix @@ -0,0 +1,23 @@ +{ + lib, + rustPlatform, + fetchCrate, +}: + +rustPlatform.buildRustPackage rec { + pname = "cargo-shear"; + version = "1.6.0"; + + src = fetchCrate { + inherit pname version; + hash = "sha256-i27DQnWCMTZ5og5KE2Fes5S7RZy/P3SwS5aEtTUoRd0="; + }; + + cargoHash = "sha256-1FuLkcYezcrzzZ7B+n5r4oY/1BI0QYwjOqUjqWopeS0="; + doCheck = false; + + meta = with lib; { + description = "Detect unused dependencies in Cargo.toml"; + mainProgram = "cargo-shear"; + }; +} From b3d90fc096361a391f8b70181ed7aaf024c5e0ab Mon Sep 17 00:00:00 2001 From: Daniel Sharifi Date: Wed, 14 Jan 2026 10:50:32 +0100 Subject: [PATCH 15/15] use versions as on CI --- flake.nix | 12 +--------- nix/cargo-shear.nix | 23 ------------------ nix/cargo-tools.nix | 58 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 34 deletions(-) delete mode 100644 nix/cargo-shear.nix create mode 100644 nix/cargo-tools.nix diff --git a/flake.nix b/flake.nix index dbec384f7d..ccdf8a6420 100644 --- a/flake.nix +++ b/flake.nix @@ -65,7 +65,7 @@ near-cli-rs = pkgs.callPackage ./nix/near-cli-rs.nix { }; # Pinned to CI version - cargo-shear = pkgs.callPackage ./nix/cargo-shear.nix { }; + cargoTools = pkgs.callPackage ./nix/cargo-tools.nix { }; libcDev = lib.getDev stdenv.cc.libc; @@ -126,16 +126,6 @@ rustPlatform.bindgenHook ]; - cargoTools = with pkgs; [ - cargo-binstall - cargo-deny - cargo-insta - cargo-make - cargo-nextest - cargo-shear - cargo-sort - ]; - nearTools = with pkgs; [ python3Packages.keyring near-cli-rs diff --git a/nix/cargo-shear.nix b/nix/cargo-shear.nix deleted file mode 100644 index 7bfbd6ea9b..0000000000 --- a/nix/cargo-shear.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ - lib, - rustPlatform, - fetchCrate, -}: - -rustPlatform.buildRustPackage rec { - pname = "cargo-shear"; - version = "1.6.0"; - - src = fetchCrate { - inherit pname version; - hash = "sha256-i27DQnWCMTZ5og5KE2Fes5S7RZy/P3SwS5aEtTUoRd0="; - }; - - cargoHash = "sha256-1FuLkcYezcrzzZ7B+n5r4oY/1BI0QYwjOqUjqWopeS0="; - doCheck = false; - - meta = with lib; { - description = "Detect unused dependencies in Cargo.toml"; - mainProgram = "cargo-shear"; - }; -} diff --git a/nix/cargo-tools.nix b/nix/cargo-tools.nix new file mode 100644 index 0000000000..82f550d713 --- /dev/null +++ b/nix/cargo-tools.nix @@ -0,0 +1,58 @@ +{ + lib, + rustPlatform, + fetchCrate, + pkgs, +}: + +let + buildTool = + { + pname, + version, + hash, + cargoHash, + }: + rustPlatform.buildRustPackage { + inherit pname version; + src = fetchCrate { + inherit pname version hash; + }; + inherit cargoHash; + doCheck = false; + }; +in +[ + (buildTool { + pname = "cargo-shear"; + version = "1.6.0"; + hash = "sha256-i27DQnWCMTZ5og5KE2Fes5S7RZy/P3SwS5aEtTUoRd0="; + cargoHash = "sha256-1FuLkcYezcrzzZ7B+n5r4oY/1BI0QYwjOqUjqWopeS0="; + }) + + (buildTool { + pname = "cargo-nextest"; + version = "0.9.106"; + hash = "sha256-J8S8Xys/GedOBNZ+MDdxtQq8C1rZOj+qpl+78fcvge0="; + cargoHash = "sha256-wDN09EKLB4jvVGNt1PvrdH9Iqe3EozCFI+wUAFjjGlM="; + }) + + (buildTool { + pname = "cargo-sort"; + version = "2.0.2"; + hash = "sha256-U/LakNUSPqj6FmYimi5ZNVJCRiS7zM4Vzvu4Gb3w38Q="; + cargoHash = "sha256-FoFzBf24mNDTRBfFyTEr9Q7sJjUhs0X/XWRGEoierQ4="; + }) + + (buildTool { + pname = "cargo-deny"; + version = "0.18.9"; + hash = "sha256-WnIkb4OXutgufNWpFooKQiJ5TNhamtTsFJu8bWyWeR4="; + cargoHash = "sha256-2u1DQtvjRfwbCXnX70M7drrMEvNsrVxsbikgrnNOkUE="; + }) + + # --- STANDARD NIXPKGS VERSIONS --- + pkgs.cargo-binstall + pkgs.cargo-insta + pkgs.cargo-make +]