python313Packages.traits: fix build (#373698)
[NixPkgs.git] / pkgs / applications / misc / electrum / default.nix
blob219046157cf8f9ef5c248517d1530f459586ad43
2   lib,
3   stdenv,
4   fetchurl,
5   protobuf,
6   wrapQtAppsHook,
7   python3,
8   zbar,
9   secp256k1,
10   enableQt ? true,
11   callPackage,
12   qtwayland,
15 let
16   libsecp256k1_name =
17     if stdenv.hostPlatform.isLinux then
18       "libsecp256k1.so.{v}"
19     else if stdenv.hostPlatform.isDarwin then
20       "libsecp256k1.{v}.dylib"
21     else
22       "libsecp256k1${stdenv.hostPlatform.extensions.sharedLibrary}";
24   libzbar_name =
25     if stdenv.hostPlatform.isLinux then
26       "libzbar.so.0"
27     else if stdenv.hostPlatform.isDarwin then
28       "libzbar.0.dylib"
29     else
30       "libzbar${stdenv.hostPlatform.extensions.sharedLibrary}";
34 python3.pkgs.buildPythonApplication rec {
35   pname = "electrum";
36   version = "4.5.8";
38   src = fetchurl {
39     url = "https://download.electrum.org/${version}/Electrum-${version}.tar.gz";
40     hash = "sha256-3YWVoTgTLe6Hzuds52Ch1iL8L9ZdO2rH335Tt/tup+g=";
41   };
43   build-system = [ protobuf ] ++ lib.optionals enableQt [ wrapQtAppsHook ];
44   buildInputs = lib.optional (stdenv.hostPlatform.isLinux && enableQt) qtwayland;
46   dependencies =
47     with python3.pkgs;
48     [
49       aiohttp
50       aiohttp-socks
51       aiorpcx
52       attrs
53       bitstring
54       cryptography
55       dnspython
56       jsonrpclib-pelix
57       matplotlib
58       pbkdf2
59       protobuf
60       pysocks
61       qrcode
62       requests
63       certifi
64       jsonpatch
65       # plugins
66       btchip-python
67       ledger-bitcoin
68       ckcc-protocol
69       keepkey
70       trezor
71       bitbox02
72       cbor2
73       pyserial
74     ]
75     ++ lib.optionals enableQt [
76       pyqt5
77       qdarkstyle
78     ];
80   checkInputs =
81     with python3.pkgs;
82     lib.optionals enableQt [
83       pyqt6
84     ];
86   postPatch =
87     ''
88       # make compatible with protobuf4 by easing dependencies ...
89       substituteInPlace ./contrib/requirements/requirements.txt \
90         --replace "protobuf>=3.20,<4" "protobuf>=3.20"
91       # ... and regenerating the paymentrequest_pb2.py file
92       protoc --python_out=. electrum/paymentrequest.proto
94       substituteInPlace ./electrum/ecc_fast.py \
95         --replace ${libsecp256k1_name} ${secp256k1}/lib/libsecp256k1${stdenv.hostPlatform.extensions.sharedLibrary}
96     ''
97     + (
98       if enableQt then
99         ''
100           substituteInPlace ./electrum/qrscanner.py \
101             --replace ${libzbar_name} ${zbar.lib}/lib/libzbar${stdenv.hostPlatform.extensions.sharedLibrary}
102         ''
103       else
104         ''
105           sed -i '/qdarkstyle/d' contrib/requirements/requirements.txt
106         ''
107     );
109   postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
110     substituteInPlace $out/share/applications/electrum.desktop \
111       --replace 'Exec=sh -c "PATH=\"\\$HOME/.local/bin:\\$PATH\"; electrum %u"' \
112                 "Exec=$out/bin/electrum %u" \
113       --replace 'Exec=sh -c "PATH=\"\\$HOME/.local/bin:\\$PATH\"; electrum --testnet %u"' \
114                 "Exec=$out/bin/electrum --testnet %u"
115   '';
117   postFixup = lib.optionalString enableQt ''
118     wrapQtApp $out/bin/electrum
119   '';
121   nativeCheckInputs = with python3.pkgs; [
122     pytestCheckHook
123     pyaes
124     pycryptodomex
125   ];
127   pytestFlagsArray = [ "tests" ];
129   postCheck = ''
130     $out/bin/electrum help >/dev/null
131   '';
133   passthru.updateScript = callPackage ./update.nix { };
135   meta = with lib; {
136     description = "Lightweight Bitcoin wallet";
137     longDescription = ''
138       An easy-to-use Bitcoin client featuring wallets generated from
139       mnemonic seeds (in addition to other, more advanced, wallet options)
140       and the ability to perform transactions without downloading a copy
141       of the blockchain.
142     '';
143     homepage = "https://electrum.org/";
144     downloadPage = "https://electrum.org/#download";
145     changelog = "https://github.com/spesmilo/electrum/blob/master/RELEASE-NOTES";
146     license = licenses.mit;
147     platforms = platforms.all;
148     maintainers = with maintainers; [
149       joachifm
150       np
151       prusnak
152       chewblacka
153     ];
154     mainProgram = "electrum";
155   };