1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchpatch2,
6 autoreconfHook,
7 pkg-config,
8 util-linux,
9 hexdump,
10 autoSignDarwinBinariesHook,
11 wrapQtAppsHook ? null,
12 boost,
13 libevent,
14 miniupnpc,
15 zeromq,
16 zlib,
17 db48,
18 sqlite,
19 qrencode,
20 qtbase ? null,
21 qttools ? null,
22 python3,
23 withGui,
24 withWallet ? true,
25}:
26
27stdenv.mkDerivation rec {
28 pname = if withGui then "elements" else "elementsd";
29 version = "23.2.4";
30
31 src = fetchFromGitHub {
32 owner = "ElementsProject";
33 repo = "elements";
34 rev = "elements-${version}";
35 sha256 = "sha256-UNjYkEZBjGuhkwBxSkNXjBBcLQqoan/afCLhoR2lOY4=";
36 };
37
38 patches = [
39 # upnp: fix build with miniupnpc 2.2.8
40 (fetchpatch2 {
41 url = "https://github.com/bitcoin/bitcoin/commit/8acdf66540834b9f9cf28f16d389e8b6a48516d5.patch?full_index=1";
42 hash = "sha256-oDvHUvwAEp0LJCf6QBESn38Bu359TcPpLhvuLX3sm6M=";
43 })
44 ];
45
46 nativeBuildInputs = [
47 autoreconfHook
48 pkg-config
49 ]
50 ++ lib.optionals stdenv.hostPlatform.isLinux [ util-linux ]
51 ++ lib.optionals stdenv.hostPlatform.isDarwin [ hexdump ]
52 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
53 autoSignDarwinBinariesHook
54 ]
55 ++ lib.optionals withGui [ wrapQtAppsHook ];
56
57 buildInputs = [
58 boost
59 libevent
60 miniupnpc
61 zeromq
62 zlib
63 ]
64 ++ lib.optionals withWallet [
65 db48
66 sqlite
67 ]
68 ++ lib.optionals withGui [
69 qrencode
70 qtbase
71 qttools
72 ];
73
74 configureFlags = [
75 "--with-boost-libdir=${boost.out}/lib"
76 "--disable-bench"
77 ]
78 ++ lib.optionals (!doCheck) [
79 "--disable-tests"
80 "--disable-gui-tests"
81 ]
82 ++ lib.optionals (!withWallet) [
83 "--disable-wallet"
84 ]
85 ++ lib.optionals withGui [
86 "--with-gui=qt5"
87 "--with-qt-bindir=${qtbase.dev}/bin:${qttools.dev}/bin"
88 ];
89
90 # fix "Killed: 9 test/test_bitcoin"
91 # https://github.com/NixOS/nixpkgs/issues/179474
92 hardeningDisable = lib.optionals (stdenv.hostPlatform.isAarch64 && stdenv.hostPlatform.isDarwin) [
93 "fortify"
94 "stackprotector"
95 ];
96
97 nativeCheckInputs = [ python3 ];
98
99 doCheck = true;
100
101 checkFlags = [
102 "LC_ALL=en_US.UTF-8"
103 ]
104 # QT_PLUGIN_PATH needs to be set when executing QT, which is needed when testing Bitcoin's GUI.
105 # See also https://github.com/NixOS/nixpkgs/issues/24256
106 ++ lib.optional withGui "QT_PLUGIN_PATH=${qtbase}/${qtbase.qtPluginPrefix}";
107
108 enableParallelBuilding = true;
109
110 meta = with lib; {
111 description = "Open Source implementation of advanced blockchain features extending the Bitcoin protocol";
112 longDescription = ''
113 The Elements blockchain platform is a collection of feature experiments and extensions to the
114 Bitcoin protocol. This platform enables anyone to build their own businesses or networks
115 pegged to Bitcoin as a sidechain or run as a standalone blockchain with arbitrary asset
116 tokens.
117 '';
118 homepage = "https://www.github.com/ElementsProject/elements";
119 maintainers = with maintainers; [ prusnak ];
120 license = licenses.mit;
121 platforms = platforms.unix;
122 };
123}