Skip to content

Commit

Permalink
WIP: build foundry from source
Browse files Browse the repository at this point in the history
It's still compiling ☕
  • Loading branch information
sveitser committed Dec 13, 2023
1 parent df569fa commit bbcf77f
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 57 deletions.
84 changes: 51 additions & 33 deletions flake.lock

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

44 changes: 20 additions & 24 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,38 @@
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flake-compat.url = "github:edolstra/flake-compat";
inputs.flake-compat.flake = false;
inputs.solc-bin.url = "github:EspressoSystems/nix-solc-bin";

inputs.foundry.url = "github:shazow/foundry.nix/monthly";

outputs = { self, flake-utils, nixpkgs, foundry, ... }:
let
goVersion = 21; # Change this to update the whole stack
overlays = [
(final: prev: {
go = prev."go_1_${toString goVersion}";
# Overlaying nodejs here to ensure nodePackages use the desired
# version of nodejs.
nodejs = prev.nodejs-16_x;
pnpm = prev.nodePackages.pnpm;
yarn = prev.nodePackages.yarn;
})
foundry.overlay
];
in
outputs = { flake-utils, nixpkgs, solc-bin, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
goVersion = 21; # Change this to update the whole stack
overlays = [
# solc-bin.overlays.default
(final: prev: {
go = prev."go_1_${toString goVersion}";
# Overlaying nodejs here to ensure nodePackages use the desired
# version of nodejs.
nodejs = prev.nodejs-18_x;
pnpm = prev.nodePackages.pnpm;
yarn = prev.nodePackages.yarn;
})
];

pkgs = import nixpkgs {
inherit overlays system;
config = {
permittedInsecurePackages = [ "nodejs-16.20.2" ];
};
};
# nixWithFlakes allows pre v2.4 nix installations to use
# flake commands (like `nix flake update`)
nixWithFlakes = pkgs.writeShellScriptBin "nix" ''
exec ${pkgs.nixFlakes}/bin/nix --experimental-features "nix-command flakes" "$@"
'';
foundry = pkgs.callPackage ./foundry { solc-bin-src = solc-bin; };
in
{
devShells.default = pkgs.mkShell {
COMPOSE_DOCKER_CLI_BUILD=1;
DOCKER_BUILDKIT=1;
COMPOSE_DOCKER_CLI_BUILD = 1;
DOCKER_BUILDKIT = 1;
packages = with pkgs; [
nixWithFlakes
go
Expand All @@ -55,8 +51,8 @@
yarn # `pnpm build` fails without this

# Foundry, and tools like the anvil dev node
foundry-bin
solc
foundry
# solc

# Docker
docker-compose # provides the `docker-compose` command
Expand Down
61 changes: 61 additions & 0 deletions foundry/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{ lib
, stdenv
, fetchFromGitHub
, rustPlatform
, rustc
, libusb1
, darwin
, solc-bin-src
}:

rustPlatform.buildRustPackage rec {
pname = "foundry";
version = "0.2.0-dev";

# To update run the following command and change `rev` and `hash`
# nix-prefetch-github foundry-rs foundry --nix --rev 3e962e2efe17396886fcb1fd141ccf4204cd3a21
src = fetchFromGitHub {
owner = "foundry-rs";
repo = "foundry";
rev = "3e962e2efe17396886fcb1fd141ccf4204cd3a21";
hash = "sha256-4ESOsNYtTPSnvtBtcXZ5FJXGCQOpW1mtlVOLyeJnLCE=";
};

cargoLock = {
lockFile = src + "/Cargo.lock";
allowBuiltinFetchGit = true;
};

nativeBuildInputs = [
libusb1
] ++ lib.optionals stdenv.isDarwin [ darwin.DarwinTools ];

buildInputs = lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.AppKit ];

# Tests fail
doCheck = false;

# Enable svm-rs to build without network access by giving it a list of solc releases.
# We take the list from our solc flake repo so that it does not update unless we want to.
# Our repo: https://github.com/EspressoSystems/nix-solc-bin
# Upstream URL: https://binaries.soliditylang.org/linux-amd64/list.json
env = let platform = if stdenv.isLinux then "linux-amd64" else "macosx-amd64"; in {
SVM_RELEASES_LIST_JSON = "${solc-bin-src}/list-${platform}.json";
# Make `vergen` produce a meaningful version.
VERGEN_BUILD_TIMESTAMP = "0";
VERGEN_BUILD_SEMVER = version;
VERGEN_GIT_SHA = src.rev;
VERGEN_GIT_COMMIT_TIMESTAMP = "0";
VERGEN_GIT_BRANCH = "master";
VERGEN_RUSTC_SEMVER = rustc.version;
VERGEN_RUSTC_CHANNEL = "stable";
VERGEN_CARGO_PROFILE = "release";
};

meta = with lib; {
description = "A blazing fast, portable and modular toolkit for Ethereum application development";
homepage = "https://github.com/foundry-rs/foundry";
license = with licenses; [ mit apsl20 ];
maintainers = [ ];
};
}

0 comments on commit bbcf77f

Please sign in to comment.