diff --git a/.gitignore b/.gitignore index 47cc9e3..980c8f8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,11 @@ dist/ # Ignore environment-specific files .env +# Ignore nixos related environment-specific files +.envrc +.cargo/ +.direnv/ + # Ignore editor-specific files .vscode/ .idea/ @@ -25,4 +30,4 @@ target/ debug/ yarn.lock -contracts/deployments/ \ No newline at end of file +contracts/deployments/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..96d4e60 --- /dev/null +++ b/flake.lock @@ -0,0 +1,146 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "foundry": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1725354688, + "narHash": "sha256-KHHFemVt6C/hbGoMzIq7cpxmjdp+KZVZaqbvx02aliY=", + "owner": "shazow", + "repo": "foundry.nix", + "rev": "671672bd60a0d2e5f6757638fdf27e806df755a4", + "type": "github" + }, + "original": { + "owner": "shazow", + "ref": "monthly", + "repo": "foundry.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1666753130, + "narHash": "sha256-Wff1dGPFSneXJLI2c0kkdWTgxnQ416KE6X4KnFkgPYQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f540aeda6f677354f1e7144ab04352f61aaa0118", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1726755586, + "narHash": "sha256-PmUr/2GQGvFTIJ6/Tvsins7Q43KTMvMFhvG6oaYK+Wk=", + "owner": "NixOs", + "repo": "nixpkgs", + "rev": "c04d5652cfa9742b1d519688f65d1bbccea9eb7e", + "type": "github" + }, + "original": { + "owner": "NixOs", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1718428119, + "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "foundry": "foundry", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1726972233, + "narHash": "sha256-FlL/bNESOtDQoczRhmPfReNAmLqVg+dAX4HectPOOf0=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "36d73192555e569d27579f6c486fea3ab768823c", + "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" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0c93896 --- /dev/null +++ b/flake.nix @@ -0,0 +1,66 @@ +{ + description = "ethereum-rs project"; + inputs = { + nixpkgs.url = "github:NixOs/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-utils.url = "github:numtide/flake-utils"; + foundry.url = "github:shazow/foundry.nix/monthly"; # Use monthly branch for permanent releases + + }; + outputs = { self, nixpkgs, rust-overlay, flake-utils, foundry, ... }@inputs: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default foundry.overlay ]; + }; + + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + cargoTomlContents = builtins.readFile ./Cargo.toml; + version = (builtins.fromTOML cargoTomlContents).package.version; + + ethereumEs = pkgs.rustPlatform.buildRustPackage { + inherit version; + name = "ethereumEs"; + buildInputs = with pkgs; [ openssl ]; + nativeBuildInputs = with pkgs; [ pkg-config openssl.dev ]; + + src = pkgs.lib.cleanSourceWith { src = self; }; + + cargoLock.lockFile = ./Cargo.lock; + + }; + in { + + overlays.default = final: prev: { ethereumEs = ethereumEs; }; + + gitRev = if (builtins.hasAttr "rev" self) then self.rev else "dirty"; + + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + foundry-bin + solc + toolchain + openssl + cargo-insta + pkg-config + eza + rust-analyzer-unwrapped + nodejs_20 + nodePackages.typescript + nodePackages.typescript-language-server + watchexec + ]; + shellHook = '' + export RUST_SRC_PATH="${toolchain}/lib/rustlib/src/rust/library" + export CARGO_HOME="$(pwd)/.cargo" + export PATH="$CARGO_HOME/bin:$PATH" + export RUST_BACKTRACE=1 + export RPC_URL='127.0.0.1:8545' + export ETHERSCAN_API_KEY='fake-key' + export HOLESKY_PRIVATE_KEY='fake-key' + export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 + ''; + }; + }); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..8e40351 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,13 @@ +[toolchain] +channel = "nightly" +components = [ + "cargo", + "clippy", + "rust-analyzer", + "rust-src", + "rust-std", + "rustc", + "rustfmt", +] +targets = [ "wasm32-unknown-unknown" ] +profile = "minimal"