diff --git a/m1/avalanche-network-runner.nix b/m1/avalanche-network-runner.nix new file mode 100644 index 00000000..012d41a3 --- /dev/null +++ b/m1/avalanche-network-runner.nix @@ -0,0 +1,28 @@ +{ pkgs ? import {} }: + +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 + ''; +} diff --git a/m1/flake.lock b/m1/flake.lock new file mode 100644 index 00000000..9e11efe5 --- /dev/null +++ b/m1/flake.lock @@ -0,0 +1,130 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1708118438, + "narHash": "sha256-kk9/0nuVgA220FcqH/D2xaN6uGyHp/zoxPNUmPCMmEE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5863c27340ba4de8f83e7e3c023b9599c3cb3c80", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1706487304, + "narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "90f456026d284c22b3e3497be980b2e47d0b28ac", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1708308739, + "narHash": "sha256-FtKWP6d51kz8282jfziNNcCBpAvEzv2TtKH6dYIXCuA=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "d45281ce1027a401255db01ea44972afbc569b7e", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/m1/flake.nix b/m1/flake.nix new file mode 100644 index 00000000..f54e4d6b --- /dev/null +++ b/m1/flake.nix @@ -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" + ''; + }; + } + ); +}