Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixify #86

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -25,4 +30,4 @@ target/
debug/

yarn.lock
contracts/deployments/
contracts/deployments/
146 changes: 146 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
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;

# GIT_COMMIT_HASH_SHORT = self.shortRev or "unknown";
kayvank marked this conversation as resolved.
Show resolved Hide resolved

};
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 CARGO_NET_GIT_FETCH_WITH_CLI=true
export ETH_RPC_URL='127.0.0.1:8545'
export ETHERSCAN_API_KEY='fake-key'
export HOLESKY_PRIVATE_KEY='fake-key'
export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could these be removed? we're likely going to have a more sophisticated setup for env vars later, and this will cause surprises

Copy link
Contributor Author

@kayvank kayvank Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that a better solution is required here @eigen-vi and I would like to work on that next.
The rust code has a few dependencies on environment variables.
I can remove them. However, the rust code is dependent on these environment variables.

'';
};
});
}
14 changes: 14 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[toolchain]
channel = "nightly"
components = [
"cargo",
"clippy",
"rust-analyzer",
"rust-src",
"rust-std",
"rustc-dev",
kayvank marked this conversation as resolved.
Show resolved Hide resolved
"rustc",
"rustfmt",
]
targets = [ "wasm32-unknown-unknown" ]
profile = "minimal"