summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/electrum-ecc/default.nix
blob: 527f3693c5118ca8d059cd4babc4043c9d8499bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
  lib,
  stdenv,
  buildPythonPackage,
  fetchPypi,
  setuptools,
  pkgs,
  pytestCheckHook,
}:

let
  libsecp256k1_name =
    if stdenv.hostPlatform.isLinux then
      "libsecp256k1.so.{v}"
    else if stdenv.hostPlatform.isDarwin then
      "libsecp256k1.{v}.dylib"
    else
      "libsecp256k1${stdenv.hostPlatform.extensions.sharedLibrary}";
in
buildPythonPackage rec {
  pname = "electrum-ecc";
  version = "0.0.5";
  pyproject = true;
  build-system = [ setuptools ];

  src = fetchPypi {
    pname = "electrum_ecc";
    inherit version;
    hash = "sha256-9zO4WWoPeyXINx0Ir2Hvece4cdW0DwWluV0tBesvt9I=";
  };

  env = {
    # Prevent compilation of the C extension as we use the system library instead.
    ELECTRUM_ECC_DONT_COMPILE = "1";
  };

  postPatch = ''
    # remove bundled libsecp256k1
    rm -rf libsecp256k1/
    # use the system library instead
    substituteInPlace ./src/electrum_ecc/ecc_fast.py \
      --replace-fail ${libsecp256k1_name} ${pkgs.secp256k1}/lib/libsecp256k1${stdenv.hostPlatform.extensions.sharedLibrary}
  '';

  nativeCheckInputs = [ pytestCheckHook ];

  pythonImportsCheck = [ "electrum_ecc" ];

  meta = {
    description = "Pure python ctypes wrapper for libsecp256k1";
    homepage = "https://github.com/spesmilo/electrum-ecc";
    license = lib.licenses.mit;
    maintainers = [ ];
  };
}