Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / applications / misc / electrum / default.nix
bloba1300983d28f2731aa227e2b008255985caf3c08
1 { lib
2 , stdenv
3 , fetchurl
4 , fetchFromGitHub
5 , wrapQtAppsHook
6 , python3
7 , zbar
8 , secp256k1
9 , enableQt ? true
10 , callPackage
13 let
14   version = "4.4.6";
16   libsecp256k1_name =
17     if stdenv.isLinux then "libsecp256k1.so.{v}"
18     else if stdenv.isDarwin then "libsecp256k1.{v}.dylib"
19     else "libsecp256k1${stdenv.hostPlatform.extensions.sharedLibrary}";
21   libzbar_name =
22     if stdenv.isLinux then "libzbar.so.0"
23     else if stdenv.isDarwin then "libzbar.0.dylib"
24     else "libzbar${stdenv.hostPlatform.extensions.sharedLibrary}";
26   # Not provided in official source releases, which are what upstream signs.
27   tests = fetchFromGitHub {
28     owner = "spesmilo";
29     repo = "electrum";
30     rev = version;
31     sha256 = "sha256-nd435CgF0a6JOni/OXcxkciVCR1aQqzfGfDSg1gPQ8Q=";
33     postFetch = ''
34       mv $out ./all
35       mv ./all/electrum/tests $out
36     '';
37   };
41 python3.pkgs.buildPythonApplication {
42   pname = "electrum";
43   inherit version;
45   src = fetchurl {
46     url = "https://download.electrum.org/${version}/Electrum-${version}.tar.gz";
47     sha256 = "sha256-BxxC1xVKToUjgBo4mEeK9Tdhbd/+doHcTTJsXDtaELg=";
48   };
50   postUnpack = ''
51     # can't symlink, tests get confused
52     cp -ar ${tests} $sourceRoot/electrum/tests
53   '';
55   nativeBuildInputs = lib.optionals enableQt [ wrapQtAppsHook ];
57   propagatedBuildInputs = with python3.pkgs; [
58     aiohttp
59     aiohttp-socks
60     aiorpcx
61     attrs
62     bitstring
63     cryptography
64     dnspython
65     jsonrpclib-pelix
66     matplotlib
67     pbkdf2
68     protobuf
69     pysocks
70     qrcode
71     requests
72     tlslite-ng
73     # plugins
74     btchip-python
75     ledger-bitcoin
76     ckcc-protocol
77     keepkey
78     trezor
79   ] ++ lib.optionals enableQt [
80     pyqt5
81     qdarkstyle
82   ];
84   postPatch = ''
85     # make compatible with protobuf4 by easing dependencies ...
86     substituteInPlace ./contrib/requirements/requirements.txt \
87       --replace "protobuf>=3.20,<4" "protobuf>=3.20"
88     # ... and regenerating the paymentrequest_pb2.py file
89     protoc --python_out=. electrum/paymentrequest.proto
91     substituteInPlace ./electrum/ecc_fast.py \
92       --replace ${libsecp256k1_name} ${secp256k1}/lib/libsecp256k1${stdenv.hostPlatform.extensions.sharedLibrary}
93   '' + (if enableQt then ''
94     substituteInPlace ./electrum/qrscanner.py \
95       --replace ${libzbar_name} ${zbar.lib}/lib/libzbar${stdenv.hostPlatform.extensions.sharedLibrary}
96   '' else ''
97     sed -i '/qdarkstyle/d' contrib/requirements/requirements.txt
98   '');
100   postInstall = lib.optionalString stdenv.isLinux ''
101     substituteInPlace $out/share/applications/electrum.desktop \
102       --replace 'Exec=sh -c "PATH=\"\\$HOME/.local/bin:\\$PATH\"; electrum %u"' \
103                 "Exec=$out/bin/electrum %u" \
104       --replace 'Exec=sh -c "PATH=\"\\$HOME/.local/bin:\\$PATH\"; electrum --testnet %u"' \
105                 "Exec=$out/bin/electrum --testnet %u"
106   '';
108   postFixup = lib.optionalString enableQt ''
109     wrapQtApp $out/bin/electrum
110   '';
112   nativeCheckInputs = with python3.pkgs; [ pytestCheckHook pyaes pycryptodomex ];
114   pytestFlagsArray = [ "electrum/tests" ];
116   postCheck = ''
117     $out/bin/electrum help >/dev/null
118   '';
120   passthru.updateScript = callPackage ./update.nix { };
122   meta = with lib; {
123     description = "Lightweight Bitcoin wallet";
124     longDescription = ''
125       An easy-to-use Bitcoin client featuring wallets generated from
126       mnemonic seeds (in addition to other, more advanced, wallet options)
127       and the ability to perform transactions without downloading a copy
128       of the blockchain.
129     '';
130     homepage = "https://electrum.org/";
131     downloadPage = "https://electrum.org/#download";
132     changelog = "https://github.com/spesmilo/electrum/blob/master/RELEASE-NOTES";
133     license = licenses.mit;
134     platforms = platforms.all;
135     maintainers = with maintainers; [ joachifm np prusnak ];
136   };