diff --git a/.travis.yml b/.travis.yml index 74cd39c8a..d5f79a26a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,8 @@ matrix: - os: osx before_install: - # - brew update + - brew update + - brew install rocksdb # - brew install gcc - git clone https://github.com/nim-lang/nim.git diff --git a/README.md b/README.md index 88eecb37e..586c62e6e 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,24 @@ Join the Status community chats: ## Building & Testing +### Prerequisites + +Please install a recent version of Facebook's RocksDB following the instructions here: + +https://github.com/facebook/rocksdb/blob/master/INSTALL.md + Currently Nimbus requires the latest development version of the Nim programming language. Follow the [installation steps](https://github.com/nim-lang/Nim) or use [choosenim](https://github.com/dom96/choosenim). +### Obtaining the prerequisites through the Nix package manager + +Users of the [Nix package manager](https://nixos.org/nix/download.html) can install all prerequisites simply by running: + +``` bash +nix-shell nimbus.nix +``` + +### Build + You can build the package and run the tests using `nimble test`. You can run the example using `nim compile --run examples/decompile_smart_contract.nim`. ## License diff --git a/default.nix b/default.nix index d489143df..3f4a659ee 100644 --- a/default.nix +++ b/default.nix @@ -1,22 +1,10 @@ -{ pkgs ? import {} }: - let - stdenv = pkgs.stdenv; + pkgs = import (builtins.fetchGit { + url = git://github.com/NixOS/nixpkgs; + rev = "8c6f9223d02c5123cbd364d6d56caca3c81416f0"; + }) {}; in -stdenv.mkDerivation rec { - name = "nimbus-${version}"; - version = "0.0.1"; - - meta = with stdenv.lib; { - description = "An Ethereum 2.0 Sharding Client for Resource-Restricted Devices"; - homepage = https://github.com/status-im/nimbus; - license = [licenses.asl20]; - platforms = platforms.unix; - }; - - src = ./.; - buildInputs = [pkgs.clang pkgs.nim pkgs.rocksdb pkgs.secp256k1 pkgs.cryptopp]; -} +import ./nimbus.nix { inherit pkgs; } diff --git a/devenv.nix b/devenv.nix deleted file mode 100644 index 5d4f511eb..000000000 --- a/devenv.nix +++ /dev/null @@ -1,10 +0,0 @@ -let - pkgs = import (builtins.fetchGit { - url = git://github.com/NixOS/nixpkgs; - rev = "8c6f9223d02c5123cbd364d6d56caca3c81416f0"; - }) {}; - -in - -import ./default.nix { inherit pkgs; } - diff --git a/nim.nix b/nim.nix new file mode 100644 index 000000000..2c0b2159d --- /dev/null +++ b/nim.nix @@ -0,0 +1,67 @@ +{ stdenv, lib, makeWrapper, nodejs, openssl, pcre, readline, sqlite, nim }: + +stdenv.mkDerivation rec { + # This derivation may be a bit confusing at first, because it builds the Status' + # Nimbus branch of Nim using the standard Nim compiler provided by Nix. + # + # It's mostly a copy of the original Nim recipe, but uses git to obtain the + # sources and have a simplified `buildPhase`. + # + # For maintainance, you only need to bump the obtained git revision from time + # to time. + + name = "status-nim"; + version = "0.18.1"; + + src = fetchGit { + url = "git://github.com/status-im/Nim"; + ref = "nimbus"; + + # Set this to the hash of the head commit in the nimbus branch: + rev = "d40fb5a6d3ed937d41fd0e72a27df8c397aae881"; + }; + + doCheck = true; + + enableParallelBuilding = true; + + NIX_LDFLAGS = [ + "-lcrypto" + "-lpcre" + "-lreadline" + "-lsqlite3" + ]; + + # 1. nodejs is only needed for tests + # 2. we could create a separate derivation for the "written in c" version of nim + # used for bootstrapping, but koch insists on moving the nim compiler around + # as part of building it, so it cannot be read-only + + buildInputs = [ + makeWrapper nodejs nim + openssl pcre readline sqlite + ]; + + buildPhase = '' + nim c --lib:"./lib" -d:release koch.nim + nim c --lib:"./lib" -d:release compiler/nim.nim && mv compiler/nim bin/ + ''; + + installPhase = '' + install -Dt $out/bin bin/* koch + ./koch install $out + mv $out/nim/bin/* $out/bin/ && rmdir $out/nim/bin + mv $out/nim/* $out/ && rmdir $out/nim + wrapProgram $out/bin/nim \ + --suffix PATH : ${lib.makeBinPath [ stdenv.cc ]} + ''; + + meta = with stdenv.lib; { + description = "Status's build of Nim"; + homepage = https://nim-lang.org/; + license = licenses.mit; + maintainers = with maintainers; [ ehmry peterhoeg ]; + platforms = with platforms; linux ++ darwin; # arbitrary + }; +} + diff --git a/nimbus.nix b/nimbus.nix new file mode 100644 index 000000000..9141bbcd4 --- /dev/null +++ b/nimbus.nix @@ -0,0 +1,23 @@ +{ pkgs ? import { } }: + +let + stdenv = pkgs.stdenv; + nim = pkgs.callPackage ./nim.nix {}; + +in + +stdenv.mkDerivation rec { + name = "nimbus-${version}"; + version = "0.0.1"; + + meta = with stdenv.lib; { + description = "An Ethereum 2.0 Sharding Client for Resource-Restricted Devices"; + homepage = https://github.com/status-im/nimbus; + license = [licenses.asl20]; + platforms = platforms.unix; + }; + + src = ./.; + buildInputs = [pkgs.clang nim pkgs.rocksdb_lite]; +} +