1{
2 stdenv,
3 fetchFromGitHub,
4 lib,
5 rustPlatform,
6 udev,
7 protobuf,
8 rocksdb_8_3,
9 installShellFiles,
10 pkg-config,
11 openssl,
12 nix-update-script,
13 versionCheckHook,
14 # Taken from https://github.com/solana-labs/solana/blob/master/scripts/cargo-install-all.sh#L84
15 solanaPkgs ? [
16 "cargo-build-bpf"
17 "cargo-test-bpf"
18 "cargo-build-sbf"
19 "cargo-test-sbf"
20 "solana"
21 "solana-bench-tps"
22 "solana-faucet"
23 "solana-gossip"
24 "solana-install"
25 "solana-keygen"
26 "solana-ledger-tool"
27 "solana-log-analyzer"
28 "solana-net-shaper"
29 "solana-validator"
30 "solana-test-validator"
31 ]
32 ++ [
33 # XXX: Ensure `solana-genesis` is built LAST!
34 # See https://github.com/solana-labs/solana/issues/5826
35 "solana-genesis"
36 ],
37}:
38let
39 version = "1.18.26";
40 hash = "sha256-sJ0Zn5GMi64/S8zqomL/dYRVW8SOQWsP+bpcdatJC0A=";
41 rocksdb = rocksdb_8_3;
42in
43rustPlatform.buildRustPackage rec {
44 pname = "solana-cli";
45 inherit version;
46
47 src = fetchFromGitHub {
48 owner = "solana-labs";
49 repo = "solana";
50 tag = "v${version}";
51 inherit hash;
52 };
53
54 # The `crossbeam-epoch@0.9.5` crate used by the solana crates is their own fork,
55 # which exists due to performance-related reasons.
56 # The `solana-cli` build fails because this forked `crossbeam-epoch` crate contains a
57 # symlink that points outside of the crate into the root of the repository.
58 # This characteristic already existed in upstream `crossbeam-epoch@0.9.5`.
59 #
60 # As `buildRustPackage` vendors the dependencies of the `solana-cli` during the `buildPhase`,
61 # which occurs after the `patchPhase`, this `crossbeam-epoch` is not patchable in this build.
62 # The remaining solution is to make use of `cargoPatches` to remove the fork and bump to `crossbeam-epoch@0.9.16`,
63 # which is the first version that removed the `build.rs`.
64 cargoPatches = [ ./crossbeam-epoch.patch ];
65
66 cargoHash = "sha256-adzcLrOiUUYhz57gme/hEmD4E3kVcKCp0/jSoavZfjw=";
67
68 strictDeps = true;
69 cargoBuildFlags = builtins.map (n: "--bin=${n}") solanaPkgs;
70
71 # Even tho the tests work, a shit ton of them try to connect to a local RPC
72 # or access internet in other ways, eventually failing due to Nix sandbox.
73 # Maybe we could restrict the check to the tests that don't require an RPC,
74 # but judging by the quantity of tests, that seems like a lengthty work and
75 # I'm not in the mood ((ΦωΦ))
76 doCheck = false;
77
78 nativeBuildInputs = [
79 installShellFiles
80 protobuf
81 pkg-config
82 ];
83 buildInputs = [
84 openssl
85 rustPlatform.bindgenHook
86 ]
87 ++ lib.optionals stdenv.hostPlatform.isLinux [ udev ];
88
89 doInstallCheck = true;
90
91 nativeInstallCheckInputs = [ versionCheckHook ];
92 versionCheckProgram = "${placeholder "out"}/bin/solana";
93 versionCheckProgramArg = "--version";
94
95 postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
96 installShellCompletion --cmd solana \
97 --bash <($out/bin/solana completion --shell bash) \
98 --fish <($out/bin/solana completion --shell fish)
99
100 mkdir -p $out/bin/sdk/bpf
101 cp -a ./sdk/bpf/* $out/bin/sdk/bpf/
102 mkdir -p $out/bin/sdk/sbf
103 cp -a ./sdk/sbf/* $out/bin/sdk/sbf
104 mkdir -p $out/bin/deps
105 find . -name libsolana_program.dylib -exec cp {} $out/bin/deps \;
106 find . -name libsolana_program.rlib -exec cp {} $out/bin/deps \;
107 '';
108
109 # Used by build.rs in the rocksdb-sys crate. If we don't set these, it would
110 # try to build RocksDB from source.
111 ROCKSDB_LIB_DIR = "${rocksdb}/lib";
112
113 # Require this on darwin otherwise the compiler starts rambling about missing
114 # cmath functions
115 CPPFLAGS = lib.optionals stdenv.hostPlatform.isDarwin "-isystem ${lib.getInclude stdenv.cc.libcxx}/include/c++/v1";
116 LDFLAGS = lib.optionals stdenv.hostPlatform.isDarwin "-L${lib.getLib stdenv.cc.libcxx}/lib";
117
118 # If set, always finds OpenSSL in the system, even if the vendored feature is enabled.
119 OPENSSL_NO_VENDOR = 1;
120
121 meta = with lib; {
122 description = "Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces";
123 homepage = "https://solana.com";
124 license = licenses.asl20;
125 maintainers = with maintainers; [
126 netfox
127 happysalada
128 aikooo7
129 ];
130 platforms = platforms.unix;
131 };
132
133 passthru.updateScript = nix-update-script { };
134}