From 0fc24169651f437175d132105ac4f81ae3d6c125 Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 4 Feb 2025 16:39:23 +0800 Subject: [PATCH] Problem: solomachine nix package don't support more platforms (#1107) * Problem: solomachine nix package don't support more platforms Solution: - build on the fly * fix solo machine path * isort * nix fmt --- integration_tests/install_solo_machine.nix | 36 ---------------------- integration_tests/shell.nix | 1 - integration_tests/test_solo_machine.py | 5 +-- nix/default.nix | 2 +- nix/solomachine.nix | 29 +++++++++++++++++ 5 files changed, 33 insertions(+), 40 deletions(-) delete mode 100644 integration_tests/install_solo_machine.nix create mode 100644 nix/solomachine.nix diff --git a/integration_tests/install_solo_machine.nix b/integration_tests/install_solo_machine.nix deleted file mode 100644 index d44a976ee..000000000 --- a/integration_tests/install_solo_machine.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ stdenv, fetchurl, lib }: -let - version = "v0.1.4"; - srcUrl = { - x86_64-linux = { - url = - "https://github.com/crypto-com/ibc-solo-machine/releases/download/${version}/ubuntu-latest-${version}.tar.gz"; - sha256 = "sha256-b+A8G7HGl1Kv32X0ybV6RODQjqAHqfAo3DQh1DtY6UQ="; - }; - x86_64-darwin = { - url = - "https://github.com/crypto-com/ibc-solo-machine/releases/download/${version}/macos-latest-${version}.tar.gz"; - sha256 = "sha256-9Zo3sGxnjB05X90FFK/3yGbWokxJqVL0teb1x1z5a0U="; - }; - aarch64-darwin = { - url = - "https://github.com/crypto-com/ibc-solo-machine/releases/download/${version}/macos-latest-${version}.tar.gz"; - sha256 = "sha256-9Zo3sGxnjB05X90FFK/3yGbWokxJqVL0teb1x1z5a0U="; - }; - }.${stdenv.system} or (throw - "Unsupported system: ${stdenv.system}"); -in -stdenv.mkDerivation { - name = "solomachine"; - inherit version; - src = fetchurl srcUrl; - sourceRoot = "."; - installPhase = '' - echo "installing solomachine ..." - echo $out - mkdir -p $out/solomachine - install -m 755 -v -D * $out/solomachine - echo `env` - ''; - meta = with lib; { platforms = with platforms; linux ++ darwin; }; -} diff --git a/integration_tests/shell.nix b/integration_tests/shell.nix index fdc1c57d3..c5ca520f1 100644 --- a/integration_tests/shell.nix +++ b/integration_tests/shell.nix @@ -20,7 +20,6 @@ pkgs.mkShell { ]; shellHook = '' export PYTHONPATH=$PWD/pystarport/proto_python/:$PYTHONPATH - export SOLO_MACHINE_HOME="${pkgs.solomachine}/solomachine" mkdir -p "$PWD/coverage" export GOCOVERDIR="$PWD/coverage" ''; diff --git a/integration_tests/test_solo_machine.py b/integration_tests/test_solo_machine.py index fc1426397..6802345ee 100644 --- a/integration_tests/test_solo_machine.py +++ b/integration_tests/test_solo_machine.py @@ -1,6 +1,7 @@ import json import os import platform +import shutil from pathlib import Path import pytest @@ -52,8 +53,8 @@ def __init__( self.chain_id = chain_id self.grpc_port = ports.grpc_port(base_port) self.rpc_port = ports.rpc_port(base_port) - self.solomachine_home = os.path.join(os.environ["SOLO_MACHINE_HOME"]) - self.bin_file = os.path.join(self.solomachine_home, "solo-machine") + self.solomachine_home = Path(shutil.which("solo-machine")).parent.parent / "lib" + self.bin_file = "solo-machine" self.mnemonic = mnemonic os_platform = platform.system() diff --git a/nix/default.nix b/nix/default.nix index df7c41eb1..404f5ef04 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -11,6 +11,7 @@ import sources.nixpkgs { doCheck = false; }; hermes = pkgs.callPackage ./hermes.nix { src = sources.ibc-rs; }; + solomachine = pkgs.callPackage ./solomachine.nix { }; }) (import "${sources.poetry2nix}/overlay.nix") (import "${sources.gomod2nix}/overlay.nix") @@ -27,7 +28,6 @@ import sources.nixpkgs { find . -name "*.nix" -type f | xargs ${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check || EXIT_STATUS=$? exit $EXIT_STATUS ''; - solomachine = pkgs.callPackage ../integration_tests/install_solo_machine.nix { }; chain-maind-zemu = pkgs.callPackage ../. { ledger_zemu = true; }; diff --git a/nix/solomachine.nix b/nix/solomachine.nix new file mode 100644 index 000000000..8157ef5bf --- /dev/null +++ b/nix/solomachine.nix @@ -0,0 +1,29 @@ +{ fetchFromGitHub +, lib +, stdenv +, darwin +, rustPlatform +, protobuf +, rustfmt +, +}: +rustPlatform.buildRustPackage rec { + pname = "ibc-solo-machine"; + version = "0.1.4"; + + src = fetchFromGitHub { + owner = "crypto-com"; + repo = pname; + rev = "v${version}"; + sha256 = "sha256-+jfRbPm31/pBuseUS89cuYSAPw2l/509MVTaUcuyaGY="; + }; + + cargoSha256 = "sha256-9Mx70yBoNy711PFC5y2VoXD3kqmcMvDsjP9AaC1VfCM="; + cargoBuildFlags = "-p solo-machine -p mnemonic-signer"; + nativeBuildInputs = [ + protobuf + rustfmt + ]; + buildInputs = lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.SystemConfiguration ]; + doCheck = false; +}