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

feat: nix development environment for subnet #114

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions m1/avalanche-network-runner.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ pkgs ? import <nixpkgs> {} }:

pkgs.buildGoModule rec {
pname = "avalanche-network-runner";
version = "1.7.5";

src = pkgs.fetchFromGitHub {
owner = "ava-labs";
repo = pname;
rev = "v${version}";
sha256 = "A54KNB9BGKvGp2UsP46U5HteiCOOKrnYatDXUAc/BIg=";
};

vendorHash = null;
vendor = true;

nativeBuildInputs = with pkgs; [git cacert blst];
buildInputs = with pkgs; [cacert blst];

buildPhase = ''
export GOPROXY=direct
go build -v -ldflags="-X 'github.com/ava-labs/avalanche-network-runner/cmd.Version=${version}'" -mod=readonly
'';

installPhase = ''
install -Dm755 ./avalanche-network-runner $out/bin/avalanche-network-runner
'';
}
130 changes: 130 additions & 0 deletions m1/flake.lock

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

93 changes: 93 additions & 0 deletions m1/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = {
self,
nixpkgs,
rust-overlay,
flake-utils,
...
}:
flake-utils.lib.eachSystem ["aarch64-darwin" "x86_64-linux"] (
system: let
overlays = [(import rust-overlay)];
pkgs = import nixpkgs {
inherit system overlays;
};
avalanche-network-runner = import ./avalanche-network-runner.nix { inherit pkgs; };

rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain;

rustPlatform = pkgs.makeRustPlatform {
cargo = rust;
rustc = rust;
};

runtimeDependencies = with pkgs; [
openssl
];

frameworks = pkgs.darwin.apple_sdk.frameworks;

buildDependencies = with pkgs; [
libclang.lib
libz
clang
pkg-config
rustPlatform.bindgenHook]
++ runtimeDependencies
++ lib.optionals stdenv.isDarwin [
frameworks.Security
frameworks.CoreServices
frameworks.SystemConfiguration
frameworks.AppKit
];

developmentDependencies = with pkgs; [
rust
avalanchego
avalanche-network-runner
]
++ buildDependencies;

subnet-cargo-toml = builtins.fromTOML (builtins.readFile ./subnet/Cargo.toml);
in
with pkgs; {
packages = flake-utils.lib.flattenTree rec {
subnet = rustPlatform.buildRustPackage {
pname = subnet-cargo-toml.package.name;
version = subnet-cargo-toml.package.version;

env = { LIBCLANG_PATH = "${libclang.lib}/lib"; }
// (lib.optionalAttrs (stdenv.cc.isClang && stdenv.isDarwin) { NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}"; });

src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};

nativeBuildInputs = buildDependencies;
buildInputs = runtimeDependencies;

doCheck = false;
};

default = subnet;
};

devShells.default = mkShell {
buildInputs = developmentDependencies;

shellHook = ''
${lib.optionalString (stdenv.cc.isClang && stdenv.isDarwin) "export NIX_LDFLAGS='-l${stdenv.cc.libcxx.cxxabi.libName}'"}
export PATH=$PATH:${avalanche-network-runner}/bin
export LIBCLANG_PATH="${pkgs.libclang.lib}/lib"
'';
};
}
);
}
Loading