Building Solana package already in nixpkgs fails in 24.05-pre

Attempting to build the Solana package on rev 87cc06983c14876bb56a6a84935d1a3968f35999 of nixpkgs which is 24.05-pre fails with an unusual error:

error: failed to run custom build command for `librocksdb-sys v0.8.0+7.4.4`

Caused by:
  process didn't exit successfully: `/build/source/target/release/build/librocksdb-sys-e5d334bfe06f60f3/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at /build/solana-cli-1.14.23-vendor.tar.gz/proc-macro2/src/fallback.rs:752:9:
  "enum_(unnamed_at_rocksdb/include/rocksdb/c_h_981_1)" is not a valid Ident

My original attempt was to upgrade the package however after various different errors attempted to build the existing one to ensure its working.

The build scripts includes the following:

  # Used by build.rs in the rocksdb-sys crate. If we don't set these, it would
  # try to build RocksDB from source.
  ROCKSDB_LIB_DIR="${rocksdb}/lib";

My assumption was that rocksdb shouldn’t even be built but unable to find a way around this.

Command to reproduce:

nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/87cc06983c14876bb56a6a84935d1a3968f35999.tar.gz -p solana-cli

Any help would be appreciated even suggestions on a possible path to debug this issue as I’m not as familiar with rust or its toolchain

Try using llvmPackages_15.clangUseLLVM

Thanks, this was resolve after upgrading to 1.16.27: solana-cli: 1.14.23 → 1.16.27 by aikooo7 · Pull Request #280788 · NixOS/nixpkgs · GitHub

Building other dependencies for Solana can be trickier and require patches, this thread has some useful insight: Any tutorials/guides on Solana development? - #32 by rollschild

if anyone comes across this and using Anchor, make sure to wrap Anchor binary with Solana’s custom rust toolchain

1 Like

hi @arijoon

I see anchor is in latest nixpkgs unstable(nixpkgs/pkgs/by-name/an/anchor/package.nix at 7bb2ccd8cdc44c91edba16c48d2c8f331fb3d856 · NixOS/nixpkgs · GitHub), do you have any example on how to wrap Anchor binary with Solana’s custom rust toolchain?

In their current state I’m not sure if anchor or solana-cli in nixpkgs can be used to compile programs
You need to do some patching as well. Issue is that Solana’s cargo-build-sbf (or bpf) will try to automatically download platform-tools (custom rustc and cargo) and link them in rustup. Either have to use rustup and let this program mutate your env or patching is required to remove all of that logic. There’s some examples in the repo above, but I created a minimal working setup you can check out here: GitHub - arijoon/solana-nix: Nix setup for Solana development

I was using an older solana version so if you’d like the latest will need to update both solana and anchor. On that repo however you should be able to run anchor init name and then build and run tests to ensure it works

There may be cleaner ways to set them up, ideally if on Solana side an env var was added for platform-tools this would be a lot simpler.

1 Like

Yes, I’m mainly blocked by build-sbf trying to download and install platform-tools on the readonly store path. The patching is nice. Thanks for this!