python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / applications / misc / electrum / default.nix
blob9421cce1d8f759110251d90d2981d60a9898b579
1 { lib
2 , stdenv
3 , fetchurl
4 , fetchFromGitHub
5 , wrapQtAppsHook
6 , python3
7 , zbar
8 , secp256k1
9 , enableQt ? true
10 # for updater.nix
11 , writeScript
12 , common-updater-scripts
13 , bash
14 , coreutils
15 , curl
16 , gnugrep
17 , gnupg
18 , gnused
19 , nix
22 let
23   version = "4.3.2";
25   libsecp256k1_name =
26     if stdenv.isLinux then "libsecp256k1.so.0"
27     else if stdenv.isDarwin then "libsecp256k1.0.dylib"
28     else "libsecp256k1${stdenv.hostPlatform.extensions.sharedLibrary}";
30   libzbar_name =
31     if stdenv.isLinux then "libzbar.so.0"
32     else if stdenv.isDarwin then "libzbar.0.dylib"
33     else "libzbar${stdenv.hostPlatform.extensions.sharedLibrary}";
35   # Not provided in official source releases, which are what upstream signs.
36   tests = fetchFromGitHub {
37     owner = "spesmilo";
38     repo = "electrum";
39     rev = version;
40     sha256 = "sha256-z2/UamKmBq/5a0PTbHdAqGK617Lc8xRhHRpbCc7jeZo=";
42     postFetch = ''
43       mv $out ./all
44       mv ./all/electrum/tests $out
45     '';
46   };
50 python3.pkgs.buildPythonApplication {
51   pname = "electrum";
52   inherit version;
54   src = fetchurl {
55     url = "https://download.electrum.org/${version}/Electrum-${version}.tar.gz";
56     sha256 = "sha256-vTZArTwbKcf6/vPQOvjubPecsg+h+QlZ6rdbl6qNfs0=";
57   };
59   postUnpack = ''
60     # can't symlink, tests get confused
61     cp -ar ${tests} $sourceRoot/electrum/tests
62   '';
64   nativeBuildInputs = lib.optionals enableQt [ wrapQtAppsHook ];
66   propagatedBuildInputs = with python3.pkgs; [
67     aiohttp
68     aiohttp-socks
69     aiorpcx
70     attrs
71     bitstring
72     cryptography
73     dnspython
74     jsonrpclib-pelix
75     matplotlib
76     pbkdf2
77     protobuf
78     pysocks
79     qrcode
80     requests
81     tlslite-ng
82     # plugins
83     btchip
84     ckcc-protocol
85     keepkey
86     trezor
87   ] ++ lib.optionals enableQt [
88     pyqt5
89     qdarkstyle
90   ];
92   postPatch = ''
93     # make compatible with protobuf4 by easing dependencies ...
94     substituteInPlace ./contrib/requirements/requirements.txt \
95       --replace "protobuf>=3.12,<4" "protobuf>=3.12"
96     # ... and regenerating the paymentrequest_pb2.py file
97     protoc --python_out=. electrum/paymentrequest.proto
99     substituteInPlace ./electrum/ecc_fast.py \
100       --replace ${libsecp256k1_name} ${secp256k1}/lib/libsecp256k1${stdenv.hostPlatform.extensions.sharedLibrary}
101   '' + (if enableQt then ''
102     substituteInPlace ./electrum/qrscanner.py \
103       --replace ${libzbar_name} ${zbar.lib}/lib/libzbar${stdenv.hostPlatform.extensions.sharedLibrary}
104   '' else ''
105     sed -i '/qdarkstyle/d' contrib/requirements/requirements.txt
106   '');
108   postInstall = lib.optionalString stdenv.isLinux ''
109     substituteInPlace $out/share/applications/electrum.desktop \
110       --replace 'Exec=sh -c "PATH=\"\\$HOME/.local/bin:\\$PATH\"; electrum %u"' \
111                 "Exec=$out/bin/electrum %u" \
112       --replace 'Exec=sh -c "PATH=\"\\$HOME/.local/bin:\\$PATH\"; electrum --testnet %u"' \
113                 "Exec=$out/bin/electrum --testnet %u"
114   '';
116   postFixup = lib.optionalString enableQt ''
117     wrapQtApp $out/bin/electrum
118   '';
120   checkInputs = with python3.pkgs; [ pytestCheckHook pyaes pycryptodomex ];
122   pytestFlagsArray = [ "electrum/tests" ];
124   postCheck = ''
125     $out/bin/electrum help >/dev/null
126   '';
128   passthru.updateScript = import ./update.nix {
129     inherit lib;
130     inherit
131       writeScript
132       common-updater-scripts
133       bash
134       coreutils
135       curl
136       gnupg
137       gnugrep
138       gnused
139       nix
140     ;
141   };
143   meta = with lib; {
144     description = "A lightweight Bitcoin wallet";
145     longDescription = ''
146       An easy-to-use Bitcoin client featuring wallets generated from
147       mnemonic seeds (in addition to other, more advanced, wallet options)
148       and the ability to perform transactions without downloading a copy
149       of the blockchain.
150     '';
151     homepage = "https://electrum.org/";
152     downloadPage = "https://electrum.org/#download";
153     changelog = "https://github.com/spesmilo/electrum/blob/master/RELEASE-NOTES";
154     license = licenses.mit;
155     platforms = platforms.all;
156     maintainers = with maintainers; [ joachifm np prusnak ];
157   };