Skip to content

Commit

Permalink
nix flake for subnet bundling avalanche
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjsbell committed Feb 20, 2024
1 parent 77d8a0c commit 6fe378a
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 0 deletions.
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.75";

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.

92 changes: 92 additions & 0 deletions m1/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
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 {
NIX_LDFLAGS="-l${stdenv.cc.libcxx.cxxabi.libName}";
buildInputs = developmentDependencies;
shellHook = ''
export PATH=$PATH:${avalanche-network-runner}/bin
export LIBCLANG_PATH="${pkgs.libclang.lib}/lib"
'';
};
}
);
}

0 comments on commit 6fe378a

Please sign in to comment.