Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nix flakes devenv #329

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8="
fi

watch_file flake.nix
dotenv_if_exists
use flake
# vi: ft=sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ types/build
types/ts-types
.dvc/
solidity-fixtures
.direnv
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ Build the node in `release mode`:
cargo build --release
```

## Installation Using Nix 💻

1. Install [Nix](https://nixos.org/download.html)
2. Enable Flakes (if you are not already see here: [Flakes](https://nixos.wiki/wiki/Flakes))
3. If you have [`direnv`](https://github.com/nix-community/nix-direnv#installation) installed, everything should work out of the box.
4. Alternatively, you can run `nix flake develop` in the root of this repo to get a shell with all the dependencies installed.
5. Happy hacking!

#### Troubleshooting for Apple Silicon users

Install Homebrew if you have not already. You can check if you have it installed with the following command:
Expand Down
85 changes: 85 additions & 0 deletions flake.lock

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

67 changes: 67 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
description = "Protocol Substrate development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
# Rust
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};

outputs = { self, nixpkgs, rust-overlay, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
lib = pkgs.lib;
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
in
{
devShells.default = pkgs.mkShell {
name = "protocol-substrate";
nativeBuildInputs = [
pkgs.protobuf
pkgs.pkg-config
# Needed for rocksdb-sys
pkgs.clang
pkgs.libclang.lib
pkgs.rustPlatform.bindgenHook
# Mold Linker for faster builds (only on Linux)
(lib.optionals pkgs.stdenv.isLinux pkgs.mold)
];
buildInputs = [
# Used for DVC
pkgs.python311
pkgs.python311Packages.pipx
# We want the unwrapped version, wrapped comes with nixpkgs' toolchain
pkgs.rust-analyzer-unwrapped
# Nodejs for test suite
pkgs.nodePackages.typescript-language-server
pkgs.nodejs_18
pkgs.nodePackages.yarn
# Finally the toolchain
toolchain
];
packages = [ ];
# Environment variables
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
# Runs DVC pull in the fixtures
# we do not install dvc globally, since it
# is broken on nixos
shellHook = ''
ROOT=$(git rev-parse --show-toplevel)
cd $ROOT/solidity-fixtures && pipx run dvc pull
cd $ROOT
cd $ROOT/substrate-fixtures && pipx run dvc pull
cd $ROOT
'';
};
});
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2022-12-26"
components = ["rustfmt", "clippy"]
components = ["rustfmt", "clippy", "rust-src"]
targets = ["wasm32-unknown-unknown"]