diff --git a/.gitignore b/.gitignore index 6e2ee700b7..e9f50b4a27 100644 --- a/.gitignore +++ b/.gitignore @@ -65,6 +65,7 @@ geth-*.zip # generated during Nim compilation *.nim.generated.nim +/result /dist /benchmark_results /.update.timestamp diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..0f60d43a34 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1712439257, + "narHash": "sha256-aSpiNepFOMk9932HOax0XwNxbA38GOUVOiXfUVPOrck=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ff0dbd94265ac470dda06a657d5fe49de93b4599", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..cab9f263d4 --- /dev/null +++ b/flake.nix @@ -0,0 +1,35 @@ +{ + description = "nimbus-eth2"; + + inputs.nixpkgs.url = github:NixOS/nixpkgs/master; + + outputs = { self, nixpkgs }: + let + stableSystems = [ + "x86_64-linux" "aarch64-linux" "armv7a-linux" + "x86_64-darwin" "aarch64-darwin" + "x86_64-windows" + ]; + forEach = nixpkgs.lib.genAttrs; + forAllSystems = forEach stableSystems; + pkgsFor = forEach stableSystems ( + system: import nixpkgs { inherit system; } + ); + in rec { + packages = forAllSystems (system: let + build = pkgsFor.${system}.callPackage ./nix/default.nix { + inherit stableSystems; src = self; + }.override; + in rec { + beacon_node = build { targets = ["nimbus_beacon_node"]; }; + signing_node = build { targets = ["nimbus_signing_node"]; }; + validator_client = build { targets = ["nimbus_validator_client"]; }; + + default = beacon_node; + }); + + devShells = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./nix/shell.nix { }; + }); + }; +} diff --git a/installer/nix/flake.lock b/installer/nix/flake.lock deleted file mode 100644 index 262f0732f3..0000000000 --- a/installer/nix/flake.lock +++ /dev/null @@ -1,61 +0,0 @@ -{ - "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1703992652, - "narHash": "sha256-C0o8AUyu8xYgJ36kOxJfXIroy9if/G6aJbNOpA5W0+M=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "32f63574c85fbc80e4ba1fbb932cde9619bad25e", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-23.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - } - }, - "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/installer/nix/flake.nix b/installer/nix/flake.nix deleted file mode 100644 index d645208761..0000000000 --- a/installer/nix/flake.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ - description = "nimbus-eth2"; - - inputs = { - nixpkgs.url = github:NixOS/nixpkgs/nixos-23.11; - flake-utils.url = github:numtide/flake-utils; - }; - - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.simpleFlake { - inherit self nixpkgs; - name = "nimbus-eth2"; - shell = ./shell.nix; - }; -} diff --git a/nix/README.md b/nix/README.md new file mode 100644 index 0000000000..02252ffa28 --- /dev/null +++ b/nix/README.md @@ -0,0 +1,29 @@ +# Usage + +## Shell + +A development shell can be started using: +```sh +nix develop +``` + +## Building + +To build a beacon node you can use: +```sh +nix build .?submodules=1 +``` +The `?submodules=1` part should eventually not be necessary. +For more details see: +https://github.com/NixOS/nix/issues/4423 + +It can be also done without even cloning the repo: +```sh +nix build github:status-im/nimbus-eth2?submodules=1 +``` + +## Running + +```sh +nix run github:status-im/nimbus-eth2?submodules=1 +``` diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000000..341d0e24b2 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,70 @@ +{ + stdenv, darwin, lib, nim1, cmake, which, writeScriptBin, + src ? ../., + # Options: nimbus_light_client, nimbus_validator_client, nimbus_signing_node, all + targets ? ["nimbus_beacon_node"], + # These are the only platforms tested in CI and considered stable. + stableSystems ? [ + "x86_64-linux" "aarch64-linux" "armv7a-linux" + "x86_64-darwin" "aarch64-darwin" + "x86_64-windows" + ], +}: + +# Nim version(s) that are known to be stable +# See: https://github.com/status-im/nimbus-build-system/commits/master/vendor +assert ( + lib.assertMsg + (builtins.elem nim1.version ["1.6.16" "1.6.18"]) + "Unsupported Nim version: ${nim1.version}" +); + +stdenv.mkDerivation rec { + pname = "nimbus-eth2"; + version = "unknown"; + + inherit src; + + # Fix for Nim compiler calling 'git rev-parse' and 'lsb_release'. + nativeBuildInputs = let + fakeGit = writeScriptBin "git" "echo ${version}"; + fakeLsbRelease = writeScriptBin "lsb_release" "echo nix"; + in + [ fakeGit fakeLsbRelease nim1 which cmake ] + ++ lib.optionals stdenv.isDarwin [ darwin.cctools ]; + + enableParallelBuilding = true; + + # Disable CPU optmizations that make binary not portable. + NIMFLAGS = "-d:disableMarchNative -d:git_revision_override=${version}"; + + makeFlags = targets ++ ["USE_SYSTEM_NIM=1"]; + + # Generate the nimbus-build-system.paths file. + configurePhase = '' + patchShebangs scripts vendor/nimbus-build-system/scripts > /dev/null + make nimbus-build-system-paths + ''; + + installPhase = '' + mkdir -p $out/bin + rm -f build/generate_makefile + cp build/* $out/bin + ''; + + meta = with lib; { + homepage = "https://nimbus.guide/"; + downloadPage = "https://github.com/status-im/nimbus-eth2/releases"; + changelog = "https://github.com/status-im/nimbus-eth2/blob/stable/CHANGELOG.md"; + description = "Nimbus is a lightweight client for the Ethereum consensus layer"; + longDescription = '' + Nimbus is an extremely efficient consensus layer client implementation. + While it's optimised for embedded systems and resource-restricted devices -- + including Raspberry Pis, its low resource usage also makes it an excellent choice + for any server or desktop (where it simply takes up fewer resources). + ''; + license = with licenses; [asl20 mit]; + mainProgram = "nimbus_beacon_node"; + platforms = stableSystems; + }; +} diff --git a/installer/nix/shell.nix b/nix/shell.nix similarity index 93% rename from installer/nix/shell.nix rename to nix/shell.nix index ea2499f81a..a2ea364aa5 100644 --- a/installer/nix/shell.nix +++ b/nix/shell.nix @@ -6,6 +6,7 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. { pkgs ? import {}}: + let mkdocs-packages = ps: with ps; [ mkdocs @@ -14,11 +15,9 @@ let pymdown-extensions ]; mkdocs-python = pkgs.python3.withPackages mkdocs-packages; -in -with pkgs; -mkShell { +in pkgs.mkShell { - buildInputs = [ + buildInputs = with pkgs; [ figlet git git-lfs @@ -43,6 +42,7 @@ mkShell { # For the purposes of compiling Nimbus, this behavior is not desired: export NIX_ENFORCE_NO_NATIVE=0 export USE_SYSTEM_GETOPT=1 + export MAKEFLAGS="-j$NIX_BUILD_CORES" figlet "Welcome to Nimbus-eth2" '';