From a47cf5aa2cc6fa4b6352ecb8697f08b9b8932441 Mon Sep 17 00:00:00 2001 From: zah Date: Sat, 15 Oct 2022 04:46:30 +0300 Subject: [PATCH] Flake-based build environment for Nix users (#3534) --- .envrc | 16 ++++++++++++++ .gitignore | 1 + env.sh | 20 ++++++++++-------- installer/nix/.gitignore | 2 ++ installer/nix/flake.lock | 43 ++++++++++++++++++++++++++++++++++++++ installer/nix/flake.nix | 15 +++++++++++++ installer/nix/shell.nix | 23 ++++++++++++++++++++ vendor/nim-nat-traversal | 2 +- vendor/nimbus-build-system | 2 +- 9 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 .envrc create mode 100644 installer/nix/.gitignore create mode 100644 installer/nix/flake.lock create mode 100644 installer/nix/flake.nix create mode 100644 installer/nix/shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..c3cc25a7c --- /dev/null +++ b/.envrc @@ -0,0 +1,16 @@ +NBS_ONLY_LOAD_ENV_VARS=1 source env.sh + +if command -v nix > /dev/null +then + export NIMBUS_NIX_ENV=1 + + cd installer/nix + # watch_file tells direnv that changes to any of the watched files + # should trigger a re-evalution of the environment + watch_file flake.nix + watch_file flake.lock + watch_file shell.nix + + mkdir -p .flake-profiles + eval "$(nix print-dev-env --profile ".flake-profiles/profile")" +fi diff --git a/.gitignore b/.gitignore index b069fa3e1..16649bf83 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ build/ # Each developer can create a personal .env file with # local settings overrides (e.g. WEB3_URL) .env +.direnv/ # Ignore dynamic, static libs and libtool archive files *.so diff --git a/env.sh b/env.sh index b3701ca74..c0466092a 100755 --- a/env.sh +++ b/env.sh @@ -7,17 +7,19 @@ ABS_PATH="$(cd ${REL_PATH}; pwd)" # Activate nvm only when this file is sourced without arguments: if [ -z "$*" ]; then - if command -v nvm > /dev/null; then - nvm use - command -v ganache-cli > /dev/null || { npm install -g ganache-cli; } - else - echo < /dev/null; then + if command -v nvm > /dev/null; then + nvm use + npm install -g ganache-cli + else + echo < { } }: with pkgs; +mkShell { + buildInputs = [ + llvmPackages_14.clang-unwrapped + figlet + git + gnumake + + # For installing ganache for local simulations + nodePackages.ganache-cli + ] ++ lib.optionals (!stdenv.isDarwin) [ + lsb-release + ]; + + shellHook = '' + # We use clang unwrapped because the compiler wrappers under Nix + # ignore -march=native in order to keep the build deterministic + export PATH=${llvmPackages_14.clang-unwrapped}/bin:$PATH + export CC=clang + + figlet "Welcome to Nimbus-eth2" + ''; +} diff --git a/vendor/nim-nat-traversal b/vendor/nim-nat-traversal index 11df74552..27d314d65 160000 --- a/vendor/nim-nat-traversal +++ b/vendor/nim-nat-traversal @@ -1 +1 @@ -Subproject commit 11df74552d3a3abe2c722c536c8075ef6814d5fa +Subproject commit 27d314d65c9078924b3239fe4e2f5af0c512b28c diff --git a/vendor/nimbus-build-system b/vendor/nimbus-build-system index 07e37730c..dc535cd46 160000 --- a/vendor/nimbus-build-system +++ b/vendor/nimbus-build-system @@ -1 +1 @@ -Subproject commit 07e37730c627c19848e8662352976afe7e15bb1f +Subproject commit dc535cd4627e6c1ec023ee6d6d0c3e5d66d414e5