forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshell.nix
139 lines (118 loc) · 3.76 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Copyright 0xB10C
{ pkgs ? import (fetchTarball "https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz") {},
bdbVersion ? "",
spareCores ? 0,
withClang ? false,
withDebug ? false,
withGui ? false,
}:
let
inherit (pkgs.lib) optionals strings;
# Add mlc binary fetching
mlcBinary = pkgs.fetchurl {
url = "https://github.com/becheran/mlc/releases/download/v0.18.0/mlc-x86_64-linux";
sha256 = "sha256-jbdp+UlFybBE+o567L398hbcWHsG8aQGqYYf5h9JRkw=";
};
# Create a derivation for mlc
mlc = pkgs.runCommand "mlc" {} ''
mkdir -p $out/bin
cp ${mlcBinary} $out/bin/mlc
chmod +x $out/bin/mlc
'';
binDirs =
[ "\$PWD/src" ]
++ optionals withGui [ "\$PWD/src/qt" ];
configureFlags =
[ "--with-boost-libdir=$NIX_BOOST_LIB_DIR" ]
++ optionals ((builtins.elem bdbVersion ["" "db48" "db5"]) || abort "Unsupported bdbVersion value: ${bdbVersion}") []
++ optionals (bdbVersion == "") [ "--without-bdb" ]
++ optionals (!(builtins.elem bdbVersion ["" "db48"])) [ "--with-incompatible-bdb" ]
++ optionals withClang [ "CXX=clang++" "CC=clang" ]
++ optionals withDebug [ "--enable-debug" ]
++ optionals withGui [
"--with-gui=qt5"
"--with-qt-bindir=${pkgs.qt5.qtbase.dev}/bin:${pkgs.qt5.qttools.dev}/bin"
];
jobs =
if (strings.hasSuffix "linux" builtins.currentSystem) then "$(($(nproc)-${toString spareCores}))"
else if (strings.hasSuffix "darwin" builtins.currentSystem) then "$(($(sysctl -n hw.physicalcpu)-${toString spareCores}))"
else "6";
in pkgs.mkShell {
nativeBuildInputs = with pkgs; [
autoconf
automake
libtool
pkg-config
boost
libevent
zeromq
sqlite
clang_18
# tests
hexdump
# compiler output caching per
# https://github.com/bitcoin/bitcoin/blob/master/doc/productivity.md#cache-compilations-with-ccache
ccache
# for newer cmake building
cmake
# depends
byacc
# debugging
gdb
# tracing
libsystemtap
linuxPackages.bpftrace
linuxPackages.bcc
]
++ lib.optionals (bdbVersion == "db48") [
db48
]
++ lib.optionals (bdbVersion == "db5") [
db5
]
++ lib.optionals withGui [
# bitcoin-qt
qt5.qtbase
# required for bitcoin-qt for "LRELEASE" etc
qt5.qttools
];
buildInputs = with pkgs; [
just
bash
# lint requirements
cargo
git
mlc
ruff
rustc
rustup
shellcheck
python310
uv
];
# Modifies the Nix clang++ wrapper to avoid warning:
# "_FORTIFY_SOURCE requires compiling with optimization (-O)"
hardeningDisable = if withDebug then [ "all" ] else [ ];
# Fixes xcb plugin error when trying to launch bitcoin-qt
QT_QPA_PLATFORM_PLUGIN_PATH = if withGui then "${pkgs.qt5.qtbase.bin}/lib/qt-${pkgs.qt5.qtbase.version}/plugins/platforms" else "";
shellHook = ''
echo "Bitcoin Core build nix-shell"
echo ""
echo "Setting up python venv"
uv venv --python 3.10
source .venv/bin/activate
uv pip install -r pyproject.toml
BCC_EGG=${pkgs.linuxPackages.bcc}/${pkgs.python3.sitePackages}/bcc-${pkgs.linuxPackages.bcc.version}-py3.${pkgs.python3.sourceVersion.minor}.egg
echo "adding bcc egg to PYTHONPATH: $BCC_EGG"
if [ -f $BCC_EGG ]; then
export PYTHONPATH="$PYTHONPATH:$BCC_EGG"
echo ""
else
echo "The bcc egg $BCC_EGG does not exist. Maybe the python or bcc version is different?"
fi
echo "adding ${builtins.concatStringsSep ":" binDirs} to \$PATH to make running built binaries more natural"
export PATH=$PATH:${builtins.concatStringsSep ":" binDirs};
rustup default stable
rustup component add rustfmt
'';
}