Skip to content

Commit

Permalink
add packages to Nix flake config, move to repo root
Browse files Browse the repository at this point in the history
This way we can actually build and run a node using just:
```sh
nix run 'github:status-im/nimbus-eth2?submodules=1'
```
The `?submodules=1` part should eventually not be necessary.
For more details see:
NixOS/nix#4423

Signed-off-by: Jakub Sokołowski <jakub@status.im>
  • Loading branch information
jakubgs committed Apr 11, 2024
1 parent e51c5ec commit 2ba3ad3
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 80 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ geth-*.zip
# generated during Nim compilation
*.nim.generated.nim

/result
/dist
/benchmark_results
/.update.timestamp
Expand Down
27 changes: 27 additions & 0 deletions flake.lock

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

38 changes: 38 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
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
buildTarget = pkgsFor.${system}.callPackage ./nix/default.nix {
inherit stableSystems; src = self;
};
build = targets: buildTarget.override { inherit targets; };
in rec {
beacon_node = build ["nimbus_beacon_node"];
signing_node = build ["nimbus_signing_node"];
validator_client = build ["nimbus_validator_client"];
ncli = build ["ncli"];
ncli_db = build ["ncli_db"];

default = beacon_node;
});

devShells = forAllSystems (system: {
default = pkgsFor.${system}.callPackage ./nix/shell.nix { };
});
};
}
61 changes: 0 additions & 61 deletions installer/nix/flake.lock

This file was deleted.

15 changes: 0 additions & 15 deletions installer/nix/flake.nix

This file was deleted.

29 changes: 29 additions & 0 deletions nix/README.md
Original file line number Diff line number Diff line change
@@ -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#beacon_node'
```
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'
```
70 changes: 70 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
stdenv, darwin, lib, nim1, cmake, which, writeScriptBin, callPackage,
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 = "${callPackage ./version.nix {}}-${src.rev or "dirty"}";

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;
};
}
8 changes: 4 additions & 4 deletions installer/nix/shell.nix → nix/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.

{ pkgs ? import <nixpkgs> {}}:

let
mkdocs-packages = ps: with ps; [
mkdocs
Expand All @@ -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
Expand All @@ -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"
'';
Expand Down
17 changes: 17 additions & 0 deletions nix/version.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ pkgs ? import <nixpkgs> { } }:

let
inherit (pkgs.lib) fileContents last splitString findSingle hasPrefix;

contents = fileContents ../beacon_chain/version.nim;
lines = splitString "\n" contents;

extractNumber = line: last (splitString " " line);
matchVersion = type: hasPrefix " version${type}";
findNumber = type: findSingle (line: matchVersion type line) "X" "X" lines;

major = extractNumber (findNumber "Major");
minor = extractNumber (findNumber "Minor");
build = extractNumber (findNumber "Build");
in
"${major}.${minor}.${build}"

0 comments on commit 2ba3ad3

Please sign in to comment.