1{
2 lib,
3 stdenv,
4 fetchurl,
5 cmake,
6 pkg-config,
7 installShellFiles,
8 autoSignDarwinBinariesHook,
9 wrapQtAppsHook ? null,
10 boost,
11 libevent,
12 zeromq,
13 zlib,
14 db48,
15 sqlite,
16 qrencode,
17 libsystemtap,
18 qtbase ? null,
19 qttools ? null,
20 python3,
21 versionCheckHook,
22 nixosTests,
23 withGui,
24 withWallet ? true,
25 enableTracing ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isStatic,
26}:
27
28let
29 desktop = fetchurl {
30 # c2e5f3e is the last commit when the debian/bitcoin-qt.desktop file was changed
31 url = "https://raw.githubusercontent.com/bitcoin-core/packaging/c2e5f3e20a8093ea02b73cbaf113bc0947b4140e/debian/bitcoin-qt.desktop";
32 sha256 = "0cpna0nxcd1dw3nnzli36nf9zj28d2g9jf5y0zl9j18lvanvniha";
33 };
34in
35stdenv.mkDerivation (finalAttrs: {
36 pname = if withGui then "bitcoin" else "bitcoind";
37 version = "29.0";
38
39 src = fetchurl {
40 urls = [
41 "https://bitcoincore.org/bin/bitcoin-core-${finalAttrs.version}/bitcoin-${finalAttrs.version}.tar.gz"
42 ];
43 # hash retrieved from signed SHA256SUMS
44 sha256 = "882c782c34a3bf2eacd1fae5cdc58b35b869883512f197f7d6dc8f195decfdaa";
45 };
46
47 nativeBuildInputs = [
48 cmake
49 pkg-config
50 installShellFiles
51 ]
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 zeromq
61 zlib
62 ]
63 ++ lib.optionals enableTracing [ libsystemtap ]
64 ++ lib.optionals withWallet [ sqlite ]
65 # building with db48 (for legacy descriptor wallet support) is broken on Darwin
66 ++ lib.optionals (withWallet && !stdenv.hostPlatform.isDarwin) [ db48 ]
67 ++ lib.optionals withGui [
68 qrencode
69 qtbase
70 qttools
71 ];
72
73 postInstall = ''
74 cd ..
75 installShellCompletion --bash contrib/completions/bash/bitcoin-cli.bash
76 installShellCompletion --bash contrib/completions/bash/bitcoind.bash
77 installShellCompletion --bash contrib/completions/bash/bitcoin-tx.bash
78
79 installShellCompletion --fish contrib/completions/fish/bitcoin-cli.fish
80 installShellCompletion --fish contrib/completions/fish/bitcoind.fish
81 installShellCompletion --fish contrib/completions/fish/bitcoin-tx.fish
82 installShellCompletion --fish contrib/completions/fish/bitcoin-util.fish
83 installShellCompletion --fish contrib/completions/fish/bitcoin-wallet.fish
84 ''
85 + lib.optionalString withGui ''
86 installShellCompletion --fish contrib/completions/fish/bitcoin-qt.fish
87
88 install -Dm644 ${desktop} $out/share/applications/bitcoin-qt.desktop
89 substituteInPlace $out/share/applications/bitcoin-qt.desktop --replace "Icon=bitcoin128" "Icon=bitcoin"
90 install -Dm644 share/pixmaps/bitcoin256.png $out/share/pixmaps/bitcoin.png
91 '';
92
93 cmakeFlags = [
94 (lib.cmakeBool "BUILD_BENCH" false)
95 (lib.cmakeBool "WITH_ZMQ" true)
96 # building with db48 (for legacy wallet support) is broken on Darwin
97 (lib.cmakeBool "WITH_BDB" (withWallet && !stdenv.hostPlatform.isDarwin))
98 (lib.cmakeBool "WITH_USDT" enableTracing)
99 ]
100 ++ lib.optionals (!finalAttrs.doCheck) [
101 (lib.cmakeBool "BUILD_TESTS" false)
102 (lib.cmakeBool "BUILD_FUZZ_BINARY" false)
103 (lib.cmakeBool "BUILD_GUI_TESTS" false)
104 ]
105 ++ lib.optionals (!withWallet) [
106 (lib.cmakeBool "ENABLE_WALLET" false)
107 ]
108 ++ lib.optionals withGui [
109 (lib.cmakeBool "BUILD_GUI" true)
110 ];
111
112 NIX_LDFLAGS = lib.optionals (
113 stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isStatic
114 ) "-levent_core";
115
116 nativeCheckInputs = [ python3 ];
117
118 doCheck = true;
119
120 checkFlags = [
121 "LC_ALL=en_US.UTF-8"
122 ]
123 # QT_PLUGIN_PATH needs to be set when executing QT, which is needed when testing Bitcoin's GUI.
124 # See also https://github.com/NixOS/nixpkgs/issues/24256
125 ++ lib.optional withGui "QT_PLUGIN_PATH=${qtbase}/${qtbase.qtPluginPrefix}";
126
127 enableParallelBuilding = true;
128
129 __darwinAllowLocalNetworking = true;
130
131 nativeInstallCheckInputs = [
132 versionCheckHook
133 ];
134 versionCheckProgram = "${placeholder "out"}/bin/bitcoin-cli";
135 versionCheckProgramArg = "--version";
136 doInstallCheck = true;
137
138 passthru.tests = {
139 smoke-test = nixosTests.bitcoind;
140 };
141
142 meta = {
143 description = "Peer-to-peer electronic cash system";
144 longDescription = ''
145 Bitcoin is a free open source peer-to-peer electronic cash system that is
146 completely decentralized, without the need for a central server or trusted
147 parties. Users hold the crypto keys to their own money and transact directly
148 with each other, with the help of a P2P network to check for double-spending.
149 '';
150 homepage = "https://bitcoin.org/en/";
151 downloadPage = "https://bitcoincore.org/bin/bitcoin-core-${finalAttrs.version}/";
152 changelog = "https://bitcoincore.org/en/releases/${finalAttrs.version}/";
153 maintainers = with lib.maintainers; [
154 prusnak
155 roconnor
156 ];
157 license = lib.licenses.mit;
158 platforms = lib.platforms.unix;
159 };
160})