diff --git a/anchor-cli.nix b/anchor-cli.nix index 0ba4733..9daa769 100644 --- a/anchor-cli.nix +++ b/anchor-cli.nix @@ -1,43 +1,29 @@ -{ stdenv -, darwin -, fetchFromGitHub -, lib -, libgcc -, pkg-config -, protobuf -, makeRustPlatform -, makeWrapper -, solana-platform-tools -, rust-bin -, udev -}: +{ stdenv, darwin, fetchFromGitHub, lib, libgcc, pkg-config, protobuf +, makeRustPlatform, makeWrapper, solana-platform-tools, rust-bin, udev }: let - # Anchor does not declare a rust-toolchain, so we have to do it here -- the - # old dependency on the `time` crate doesn't support Rust versions >= 1.80. + # nixpkgs 24.11 defaults to Rust v1.82.0 + # Anchor does not declare a rust-toolchain, so we do it here -- the code + # mentions Rust 1.85.0 at https://github.com/coral-xyz/anchor/blob/c509618412e004415c7b090e469a9e4d5177f642/docs/content/docs/installation.mdx?plain=1#L31 rustPlatform = makeRustPlatform { - cargo = rust-bin.stable."1.79.0".default; - rustc = rust-bin.stable."1.79.0".default; + cargo = rust-bin.stable."1.85.0".default; + rustc = rust-bin.stable."1.85.0".default; }; -in -rustPlatform.buildRustPackage rec { +in rustPlatform.buildRustPackage rec { pname = "anchor-cli"; - version = "0.30.1"; + version = "0.31.0"; doCheck = false; nativeBuildInputs = [ protobuf pkg-config makeWrapper ]; - buildInputs = [ ] - ++ lib.optionals stdenv.isLinux [ udev ] - ++ lib.optional - stdenv.isDarwin [ - darwin.apple_sdk.frameworks.CoreFoundation - ]; + buildInputs = [ ] ++ lib.optionals stdenv.isLinux [ udev ] + ++ lib.optional stdenv.isDarwin + [ darwin.apple_sdk.frameworks.CoreFoundation ]; src = fetchFromGitHub { owner = "coral-xyz"; repo = "anchor"; rev = "v${version}"; - hash = "sha256-3fLYTJDVCJdi6o0Zd+hb9jcPDKm4M4NzpZ8EUVW/GVw="; + hash = "sha256-CaBVdp7RPVmzzEiVazjpDLJxEkIgy1BHCwdH2mYLbGM="; }; cargoLock = { @@ -45,20 +31,16 @@ rustPlatform.buildRustPackage rec { allowBuiltinFetchGit = true; }; - patches = [ - ./anchor-cli.patch - ]; + patches = [ ./anchor-cli.patch ]; buildAndTestSubdir = "cli"; # Ensure anchor has access to Solana's cargo and rust binaries postInstall = '' - rust=${solana-platform-tools}/bin/sdk/sbf/dependencies/platform-tools/rust/bin + rust=${solana-platform-tools}/bin/platform-tools-sdk/sbf/dependencies/platform-tools/rust/bin wrapProgram $out/bin/anchor \ --prefix PATH : "$rust" ''; - meta = { - description = "Anchor cli"; - }; + meta = { description = "Anchor cli"; }; } diff --git a/anchor-cli.patch b/anchor-cli.patch index f6c1e02..dbd43b3 100644 --- a/anchor-cli.patch +++ b/anchor-cli.patch @@ -1,28 +1,49 @@ +diff --git a/cli/src/lib.rs b/cli/src/lib.rs +index 3404b032..4d87ed96 100644 +--- a/cli/src/lib.rs ++++ b/cli/src/lib.rs +@@ -1821,6 +1821,8 @@ fn docker_build_bpf( + container_name, + "cargo", + subcommand, ++ "--skip-tools-install", ++ "--no-rustup-override", + "--manifest-path", + &manifest_path.display().to_string(), + ]) +@@ -1923,6 +1925,8 @@ fn _build_rust_cwd( + ) -> Result<()> { + let exit = std::process::Command::new("cargo") + .arg(arch.build_subcommand()) ++ .arg("--skip-tools-install") ++ .arg("--no-rustup-override") + .args(cargo_args.clone()) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) diff --git a/idl/src/build.rs b/idl/src/build.rs -index 96dc3db2..1b098718 100644 +index ccd89745..2d679123 100644 --- a/idl/src/build.rs +++ b/idl/src/build.rs -@@ -60,16 +60,8 @@ pub fn build_idl( - - /// Build IDL. - fn build(program_path: &Path, resolution: bool, skip_lint: bool, no_docs: bool) -> Result { +@@ -138,15 +138,8 @@ fn build( + no_docs: bool, + cargo_args: &[String], + ) -> Result { - // `nightly` toolchain is currently required for building the IDL. - let toolchain = std::env::var("RUSTUP_TOOLCHAIN") - .map(|toolchain| format!("+{}", toolchain)) - .unwrap_or_else(|_| "+nightly".to_string()); - - install_toolchain_if_needed(&toolchain)?; -- let output = Command::new("cargo") .args([ - &toolchain, "test", "__anchor_private_print_idl", "--features", -@@ -202,23 +194,6 @@ fn build(program_path: &Path, resolution: bool, skip_lint: bool, no_docs: bool) +@@ -283,23 +276,6 @@ fn build( idl.ok_or_else(|| anyhow!("IDL doesn't exist")) } - + -/// Install the given toolchain if it's not already installed. -fn install_toolchain_if_needed(toolchain: &str) -> Result<()> { - let is_installed = Command::new("cargo") @@ -43,3 +64,11 @@ index 96dc3db2..1b098718 100644 /// Convert paths to name if there are no conflicts. fn convert_module_paths(idl: Idl) -> Idl { let idl = serde_json::to_string(&idl).unwrap(); +diff --git a/rust-toolchain.toml b/rust-toolchain.toml +new file mode 100644 +index 00000000..c1bc0a69 +--- /dev/null ++++ b/rust-toolchain.toml +@@ -0,0 +1,2 @@ ++[toolchain] ++channel = "1.85.0" diff --git a/cargo-build-sbf.patch b/cargo-build-sbf.patch deleted file mode 100644 index 0fa1af0..0000000 --- a/cargo-build-sbf.patch +++ /dev/null @@ -1,131 +0,0 @@ -diff --git a/sdk/cargo-build-sbf/src/main.rs b/sdk/cargo-build-sbf/src/main.rs -index 03bfce2cab..0485721b4a 100644 ---- a/sdk/cargo-build-sbf/src/main.rs -+++ b/sdk/cargo-build-sbf/src/main.rs -@@ -5,7 +5,6 @@ use { - itertools::Itertools, - log::*, - regex::Regex, -- solana_download_utils::download_file, - solana_sdk::signature::{write_keypair_file, Keypair}, - std::{ - borrow::Cow, -@@ -255,96 +254,13 @@ fn make_platform_tools_path_for_version(package: &str, version: &str) -> PathBuf - - // Check whether a package is installed and install it if missing. - fn install_if_missing( -- config: &Config, -- package: &str, -- url: &str, -- download_file_name: &str, -- platform_tools_version: &str, -- target_path: &Path, -+ _config: &Config, -+ _package: &str, -+ _url: &str, -+ _download_file_name: &str, -+ _platform_tools_version: &str, -+ _target_path: &Path, - ) -> Result<(), String> { -- if config.force_tools_install { -- if target_path.is_dir() { -- debug!("Remove directory {:?}", target_path); -- fs::remove_dir_all(target_path).map_err(|err| err.to_string())?; -- } -- let source_base = config.sbf_sdk.join("dependencies"); -- if source_base.exists() { -- let source_path = source_base.join(package); -- if source_path.exists() { -- debug!("Remove file {:?}", source_path); -- fs::remove_file(source_path).map_err(|err| err.to_string())?; -- } -- } -- } -- // Check whether the target path is an empty directory. This can -- // happen if package download failed on previous run of -- // cargo-build-sbf. Remove the target_path directory in this -- // case. -- if target_path.is_dir() -- && target_path -- .read_dir() -- .map_err(|err| err.to_string())? -- .next() -- .is_none() -- { -- debug!("Remove directory {:?}", target_path); -- fs::remove_dir(target_path).map_err(|err| err.to_string())?; -- } -- -- // Check whether the package is already in ~/.cache/solana. -- // Download it and place in the proper location if not found. -- if !target_path.is_dir() -- && !target_path -- .symlink_metadata() -- .map(|metadata| metadata.file_type().is_symlink()) -- .unwrap_or(false) -- { -- if target_path.exists() { -- debug!("Remove file {:?}", target_path); -- fs::remove_file(target_path).map_err(|err| err.to_string())?; -- } -- fs::create_dir_all(target_path).map_err(|err| err.to_string())?; -- let mut url = String::from(url); -- url.push('/'); -- url.push_str(platform_tools_version); -- url.push('/'); -- url.push_str(download_file_name); -- let download_file_path = target_path.join(download_file_name); -- if download_file_path.exists() { -- fs::remove_file(&download_file_path).map_err(|err| err.to_string())?; -- } -- download_file(url.as_str(), &download_file_path, true, &mut None)?; -- let zip = File::open(&download_file_path).map_err(|err| err.to_string())?; -- let tar = BzDecoder::new(BufReader::new(zip)); -- let mut archive = Archive::new(tar); -- archive.unpack(target_path).map_err(|err| err.to_string())?; -- fs::remove_file(download_file_path).map_err(|err| err.to_string())?; -- } -- // Make a symbolic link source_path -> target_path in the -- // sdk/sbf/dependencies directory if no valid link found. -- let source_base = config.sbf_sdk.join("dependencies"); -- if !source_base.exists() { -- fs::create_dir_all(&source_base).map_err(|err| err.to_string())?; -- } -- let source_path = source_base.join(package); -- // Check whether the correct symbolic link exists. -- let invalid_link = if let Ok(link_target) = source_path.read_link() { -- if link_target.ne(target_path) { -- fs::remove_file(&source_path).map_err(|err| err.to_string())?; -- true -- } else { -- false -- } -- } else { -- true -- }; -- if invalid_link { -- #[cfg(unix)] -- std::os::unix::fs::symlink(target_path, source_path).map_err(|err| err.to_string())?; -- #[cfg(windows)] -- std::os::windows::fs::symlink_dir(target_path, source_path) -- .map_err(|err| err.to_string())?; -- } - Ok(()) - } - -@@ -680,7 +596,6 @@ fn build_solana_package( - error!("Failed to install platform-tools: {}", err); - exit(1); - }); -- link_solana_toolchain(config); - - let llvm_bin = config - .sbf_sdk -@@ -738,7 +653,6 @@ fn build_solana_package( - - let cargo_build = PathBuf::from("cargo"); - let mut cargo_build_args = vec![ -- "+solana", - "build", - "--release", - "--target", diff --git a/criterion.nix b/criterion.nix index f051662..e66cf04 100644 --- a/criterion.nix +++ b/criterion.nix @@ -1,9 +1,4 @@ -{ lib -, fetchFromGitHub -, cmake -, pkg-config -, criterion -}: +{ lib, fetchFromGitHub, cmake, pkg-config, criterion }: criterion.overrideAttrs rec { version = "2.3.3"; diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0fa807a --- /dev/null +++ b/flake.lock @@ -0,0 +1,98 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1741352980, + "narHash": "sha256-+u2UunDA4Cl5Fci3m7S643HzKmIDAe+fiXrLqYsR2fs=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "f4330d22f1c5d2ba72d3d22df5597d123fdb60a9", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "f4330d22f1c5d2ba72d3d22df5597d123fdb60a9", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1742316870, + "narHash": "sha256-D1YCphhrAP0Z96X9XmqqjIS/PIv5t0Nok6NkcTOsgP0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "c5e2528c7c4ec05ce05a563e3be64f3525b278ad", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "rev": "c5e2528c7c4ec05ce05a563e3be64f3525b278ad", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1740877520, + "narHash": "sha256-oiwv/ZK/2FhGxrCkQkB83i7GnWXPPLzoqFHpDD3uYpk=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "147dee35aab2193b174e4c0868bd80ead5ce755c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1736320768, + "narHash": "sha256-nIYdTAiKIGnFNugbomgBJR+Xv5F1ZQU+HfaBqJKroC0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4bc9c909d9ac828a039f288cf872d16d38185db8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1742265167, + "narHash": "sha256-RB0UEF9IXIgwuuBFC+s9H4rDyvmMZePHlBAK4vRAwf4=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "87f0965f9f5b13fca9f38074eee8369dc767550d", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "87f0965f9f5b13fca9f38074eee8369dc767550d", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d2926a1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,46 @@ +{ + description = "Solana development setup with Nix."; + inputs = { + nixpkgs.url = + "github:nixos/nixpkgs/c5e2528c7c4ec05ce05a563e3be64f3525b278ad"; + flake-parts.url = + "github:hercules-ci/flake-parts/f4330d22f1c5d2ba72d3d22df5597d123fdb60a9"; + rust-overlay.url = + "github:oxalica/rust-overlay/87f0965f9f5b13fca9f38074eee8369dc767550d"; + }; + outputs = inputs@{ self, nixpkgs, flake-parts, rust-overlay }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + "x86_64-windows" + ]; + perSystem = { config, self', inputs', pkgs, system, ... }: + with import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + let + solana-source = callPackage (import ./solana-source.nix) { }; + solana-platform-tools = + callPackage (import ./solana-platform-tools.nix) { + inherit solana-source; + }; + solana-rust = callPackage (import ./solana-rust.nix) { + inherit solana-platform-tools; + }; + solana-cli = callPackage (import ./solana-cli.nix) { + inherit solana-platform-tools solana-source; + }; + anchor-cli = callPackage (import ./anchor-cli.nix) { + inherit solana-platform-tools; + }; + in { + devShells.default = mkShell { + packages = [ anchor-cli solana-cli solana-rust yarn nodejs ]; + }; + }; + }; +} diff --git a/nix/sources.json b/nix/sources.json index 68ffe8d..5dea1e1 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -5,10 +5,10 @@ "homepage": "", "owner": "nixos", "repo": "nixpkgs", - "rev": "c387cc8d7f36f39c664ec4ebd31bbd599afee63a", - "sha256": "0mjdqjwax51h93kibn533wrl12zc5i81aa2sw1hw072690w1lcqr", + "rev": "8b27c1239e5c421a2bbc2c65d52e4a6fbf2ff296", + "sha256": "1gx0hihb7kcddv5h0k7dysp2xhf1ny0aalxhjbpj2lmvj7h9g80a", "type": "tarball", - "url": "https://github.com/nixos/nixpkgs/archive/c387cc8d7f36f39c664ec4ebd31bbd599afee63a.tar.gz", + "url": "https://github.com/nixos/nixpkgs/archive/8b27c1239e5c421a2bbc2c65d52e4a6fbf2ff296.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "rust_overlay": { @@ -17,10 +17,10 @@ "homepage": "", "owner": "oxalica", "repo": "rust-overlay", - "rev": "dd236609a6c272d00ceaa042b1a81a31968e7f4d", - "sha256": "14sr0bhqjn7yg6gkn6cxxmkb5l0ncd6n7rxx41d07wfv7ycn325f", + "rev": "954582a766a50ebef5695a9616c93b5386418c08", + "sha256": "0g3wvgplicyjhzmh6fj9cypl2ihld372bzyxc548njq3v8qjfsjb", "type": "tarball", - "url": "https://github.com/oxalica/rust-overlay/archive/dd236609a6c272d00ceaa042b1a81a31968e7f4d.tar.gz", + "url": "https://github.com/oxalica/rust-overlay/archive/954582a766a50ebef5695a9616c93b5386418c08.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/pkgs.nix b/pkgs.nix index 3aff009..ce29113 100644 --- a/pkgs.nix +++ b/pkgs.nix @@ -1,23 +1,18 @@ -{ sources ? import ./nix/sources.nix -, config ? { } -, system ? builtins.currentSystem -, -}: +{ sources ? import ./nix/sources.nix, config ? { } +, system ? builtins.currentSystem, }: let nixpkgs = sources.nixpkgs; rust_overlay = import (sources.rust_overlay); overlays = [ (self: super: { - criterion = self.callPackage (import ./criterion.nix) { criterion = super.criterion; }; solana-source = self.callPackage (import ./solana-source.nix) { }; - solana-platform-tools = self.callPackage (import ./solana-platform-tools.nix) { }; + solana-platform-tools = + self.callPackage (import ./solana-platform-tools.nix) { }; solana-rust = self.callPackage (import ./solana-rust.nix) { }; solana-cli = self.callPackage (import ./solana-cli.nix) { }; anchor-cli = self.callPackage (import ./anchor-cli.nix) { }; - } - ) + }) rust_overlay ]; -in -import nixpkgs { inherit config system overlays; } +in import nixpkgs { inherit config system overlays; } diff --git a/shell.nix b/shell.nix index aa01ef9..a3221f2 100644 --- a/shell.nix +++ b/shell.nix @@ -1,13 +1,4 @@ -let - pkgs = import ./pkgs.nix { }; -in -pkgs.mkShell { - buildInputs = with pkgs; [ - anchor-cli - solana-cli - solana-rust - - yarn - nodejs - ]; +let pkgs = import ./pkgs.nix { }; +in pkgs.mkShell { + buildInputs = with pkgs; [ anchor-cli solana-cli solana-rust yarn nodejs ]; } diff --git a/solana-cli.nix b/solana-cli.nix index 1247b87..92b7804 100644 --- a/solana-cli.nix +++ b/solana-cli.nix @@ -1,123 +1,111 @@ # https://github.com/NixOS/nixpkgs/blob/nixos-23.11/pkgs/applications/blockchains/solana/default.nix -({ stdenv - , rustPlatform - , fetchFromGitHub - , lib - , libgcc - , darwin - , clang - , udev - , protobuf - , libcxx - , rocksdb_8_11 - , snappy - , pkg-config - , makeWrapper - , solana-platform-tools - , solana-source - , openssl - , nix-update-script - # Taken from https://github.com/solana-labs/solana/blob/master/scripts/cargo-install-all.sh#L84 - , solanaPkgs ? [ - "agave-install" - "agave-install-init" - "agave-ledger-tool" - "agave-validator" - "agave-watchtower" - "cargo-build-sbf" - "cargo-test-sbf" - "rbpf-cli" - "solana" - "solana-bench-tps" - "solana-faucet" - "solana-gossip" - "solana-keygen" - "solana-log-analyzer" - "solana-net-shaper" - "solana-dos" - "solana-stake-accounts" - "solana-test-validator" - "solana-tokens" - "solana-genesis" - ] - }: -let - version = solana-source.version; +({ stdenv, makeRustPlatform, rust-bin, fetchFromGitHub, lib, libgcc, darwin + , clang, udev, protobuf, libcxx, rocksdb_8_11, snappy, pkg-config, makeWrapper + , solana-platform-tools, solana-source, openssl, nix-update-script + # Taken from https://github.com/solana-labs/solana/blob/master/scripts/cargo-install-all.sh#L84 + , solanaPkgs ? [ + "agave-install" + "agave-install-init" + "agave-ledger-tool" + "agave-validator" + "agave-watchtower" + "cargo-build-sbf" + "cargo-test-sbf" + "rbpf-cli" + "solana" + "solana-bench-tps" + "solana-faucet" + "solana-gossip" + "solana-keygen" + "solana-log-analyzer" + "solana-net-shaper" + "solana-dos" + "solana-stake-accounts" + "solana-test-validator" + "solana-tokens" + "solana-genesis" + ] }: + let + version = solana-source.version; - inherit (darwin.apple_sdk_11_0) Libsystem; - inherit (darwin.apple_sdk_11_0.frameworks) System IOKit AppKit Security; -in -rustPlatform.buildRustPackage rec { - pname = "solana-cli"; - inherit version; + # nixpkgs 24.11 defaults to Rust v1.82.0, but Agave uses Rust v1.84.1 + rustPlatform = makeRustPlatform { + cargo = rust-bin.stable."1.84.1".default; + rustc = rust-bin.stable."1.84.1".default; + }; - src = solana-source.src; + inherit (darwin.apple_sdk_11_0) Libsystem; + inherit (darwin.apple_sdk_11_0.frameworks) System IOKit AppKit Security; + in rustPlatform.buildRustPackage rec { + pname = "solana-cli"; + inherit version; - cargoLock = { - lockFile = "${src.outPath}/Cargo.lock"; - outputHashes = { - "crossbeam-epoch-0.9.5" = "sha256-Jf0RarsgJiXiZ+ddy0vp4jQ59J9m0k3sgXhWhCdhgws="; - }; - }; + src = solana-source.src; - patches = [ - ./cargo-build-sbf.patch - ]; + cargoLock = { + lockFile = "${src.outPath}/Cargo.lock"; + outputHashes = { + "crossbeam-epoch-0.9.5" = + "sha256-Jf0RarsgJiXiZ+ddy0vp4jQ59J9m0k3sgXhWhCdhgws="; + }; + }; - strictDeps = true; - cargoBuildFlags = builtins.map (n: "--bin=${n}") solanaPkgs; + strictDeps = true; + cargoBuildFlags = builtins.map (n: "--bin=${n}") solanaPkgs; - # Even tho the tests work, a shit ton of them try to connect to a local RPC - # or access internet in other ways, eventually failing due to Nix sandbox. - # Maybe we could restrict the check to the tests that don't require an RPC, - # but judging by the quantity of tests, that seems like a lengthty work and - # I'm not in the mood ((ΦωΦ)) - doCheck = false; + # Even tho the tests work, a shit ton of them try to connect to a local RPC + # or access internet in other ways, eventually failing due to Nix sandbox. + # Maybe we could restrict the check to the tests that don't require an RPC, + # but judging by the quantity of tests, that seems like a lengthty work and + # I'm not in the mood ((ΦωΦ)) + doCheck = false; - nativeBuildInputs = [ protobuf pkg-config ]; - buildInputs = [ openssl rustPlatform.bindgenHook makeWrapper ] - ++ lib.optionals stdenv.isLinux [ udev ] - ++ lib.optionals stdenv.isDarwin [ - libcxx - IOKit - Security - AppKit - System - Libsystem - ]; -# wrapProgram $out/bin/tailscaled --prefix PATH : ${pkgs.lib.makeBinPath + nativeBuildInputs = [ protobuf pkg-config ]; + buildInputs = [ openssl rustPlatform.bindgenHook makeWrapper ] + ++ lib.optionals stdenv.isLinux [ udev ] + ++ lib.optionals stdenv.isDarwin [ + libcxx + IOKit + Security + AppKit + System + Libsystem + ]; + # wrapProgram $out/bin/tailscaled --prefix PATH : ${pkgs.lib.makeBinPath - postInstall = '' - mkdir -p $out/bin/sdk/sbf - cp -a ./sdk/sbf/* $out/bin/sdk/sbf/ + postInstall = '' + mkdir -p $out/bin/platform-tools-sdk/sbf + cp -a ./platform-tools-sdk/sbf/* $out/bin/platform-tools-sdk/sbf/ - rust=${solana-platform-tools}/bin/sdk/sbf/dependencies/platform-tools/rust/bin - sbfsdkdir=${solana-platform-tools}/bin/sdk/sbf - wrapProgram $out/bin/cargo-build-sbf \ - --prefix PATH : "$rust" \ - --set SBF_SDK_PATH "$sbfsdkdir" - ''; + rust=${solana-platform-tools}/bin/platform-tools-sdk/sbf/dependencies/platform-tools/rust/bin + sbfsdkdir=${solana-platform-tools}/bin/platform-tools-sdk/sbf + wrapProgram $out/bin/cargo-build-sbf \ + --prefix PATH : "$rust" \ + --set SBF_SDK_PATH "$sbfsdkdir" + ''; - # 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_8_11}/lib"; - ROCKSDB_INCLUDE_DIR = "${rocksdb_8_11}/include"; + # 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_8_11}/lib"; + ROCKSDB_INCLUDE_DIR = "${rocksdb_8_11}/include"; - # Require this on darwin otherwise the compiler starts rambling about missing - # cmath functions - CPPFLAGS = lib.optionals stdenv.isDarwin "-isystem ${lib.getDev libcxx}/include/c++/v1"; - LDFLAGS = lib.optionals stdenv.isDarwin "-L${lib.getLib libcxx}/lib"; + # Require this on darwin otherwise the compiler starts rambling about missing + # cmath functions + CPPFLAGS = lib.optionals stdenv.isDarwin + "-isystem ${lib.getDev libcxx}/include/c++/v1"; + LDFLAGS = lib.optionals stdenv.isDarwin "-L${lib.getLib libcxx}/lib"; - # If set, always finds OpenSSL in the system, even if the vendored feature is enabled. - OPENSSL_NO_VENDOR = 1; + # If set, always finds OpenSSL in the system, even if the vendored feature is enabled. + OPENSSL_NO_VENDOR = 1; - meta = with lib; { - description = "Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces. "; - homepage = "https://solana.com"; - license = licenses.asl20; - maintainers = with maintainers; [ netfox happysalada ]; - platforms = platforms.unix; - }; + meta = with lib; { + description = + "Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces. "; + homepage = "https://solana.com"; + license = licenses.asl20; + maintainers = with maintainers; [ netfox happysalada ]; + platforms = platforms.unix; + }; - passthru.updateScript = nix-update-script { }; -}) + passthru.updateScript = nix-update-script { }; + }) diff --git a/solana-platform-tools.nix b/solana-platform-tools.nix index 6fecc22..0550fac 100644 --- a/solana-platform-tools.nix +++ b/solana-platform-tools.nix @@ -1,80 +1,71 @@ -({ stdenv - , autoPatchelfHook - , criterion - , fetchzip - , lib - , libclang - , libedit - , python310 - , solana-source - , udev - , xz - , zlib - , system ? builtins.currentSystem - }: -let - version = "v1.43"; - sha256 = "GhMnfjKNJXpVqT1CZE0Zyp4+NXJG41sUxwHye9DGPt0="; -in -stdenv.mkDerivation rec { - pname = "solana-platform-tools"; - inherit version; +({ stdenv, autoPatchelfHook, criterion, fetchzip, lib, libclang, libedit + , python310, solana-source, udev, xz, zlib, system ? builtins.currentSystem }: + let + version = "v1.45"; + sha256 = "sha256-aJjYD4vhsLcBMAC8hXrecrMvyzbkas9VNF9nnNxtbiE="; + in stdenv.mkDerivation rec { + pname = "solana-platform-tools"; + inherit version; - src = - let + src = let # The system string is inverted - # TODO add darwin equivalent here systemMapping = { x86_64-linux = "linux-x86_64"; + aarch64-linux = "linux-aarch64"; + x86_64-darwin = "osx-x86_64"; + aarch64-darwin = "osx-aarch64"; + x86_64-windows = "windows-x86_64"; }; - in - fetchzip { - url = "https://github.com/anza-xyz/platform-tools/releases/download/${version}/platform-tools-${systemMapping."${system}"}.tar.bz2"; + in fetchzip { + url = + "https://github.com/anza-xyz/platform-tools/releases/download/${version}/platform-tools-${ + systemMapping."${system}" + }.tar.bz2"; inherit sha256; stripRoot = false; }; - doCheck = false; + doCheck = false; - nativeBuildInputs = [ autoPatchelfHook ]; + nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ]; - buildInputs = [ - # Auto patching - libedit - zlib - stdenv.cc.cc - libclang.lib - xz - python310 - ] ++ lib.optionals stdenv.isLinux [ udev ]; + buildInputs = [ + # Auto patching + libedit + zlib + stdenv.cc.cc + libclang.lib + xz + python310 + ] ++ lib.optionals stdenv.isLinux [ udev ]; - installPhase = '' - platformtools=$out/bin/sdk/sbf/dependencies/platform-tools - mkdir -p $platformtools - cp -r $src/llvm $platformtools - cp -r $src/rust $platformtools - chmod 0755 -R $out - touch $platformtools-${version}.md + installPhase = '' + platformtools=$out/bin/platform-tools-sdk/sbf/dependencies/platform-tools + mkdir -p $platformtools + cp -r $src/llvm $platformtools + cp -r $src/rust $platformtools + chmod 0755 -R $out + touch $platformtools-${version}.md - # Criterion is also needed - criterion=$out/bin/sdk/sbf/dependencies/criterion - mkdir $criterion - ln -s ${criterion.dev}/include $criterion/include - ln -s ${criterion}/lib $criterion/lib - ln -s ${criterion}/share $criterion/share - touch $criterion-v${criterion.version}.md + # Criterion is also needed + criterion=$out/bin/platform-tools-sdk/sbf/dependencies/criterion + mkdir $criterion + ln -s ${criterion.dev}/include $criterion/include + ln -s ${criterion}/lib $criterion/lib + ln -s ${criterion}/share $criterion/share + touch $criterion-v${criterion.version}.md - cp -ar ${solana-source.src}/sdk/sbf/* $out/bin/sdk/sbf/ - ''; + cp -ar ${solana-source.src}/platform-tools-sdk/sbf/* $out/bin/platform-tools-sdk/sbf/ + ''; - # A bit ugly, but liblldb.so uses libedit.so.2 and nix provides libedit.so - postFixup = '' - patchelf --replace-needed libedit.so.2 libedit.so $out/bin/sdk/sbf/dependencies/platform-tools/llvm/lib/liblldb.so.18.1.7-rust-dev - ''; + # A bit ugly, but liblldb.so uses libedit.so.2 and nix provides libedit.so + postFixup = lib.optionals stdenv.isLinux '' + patchelf --replace-needed libedit.so.2 libedit.so $out/bin/platform-tools-sdk/sbf/dependencies/platform-tools/llvm/lib/liblldb.so.18.1.7-rust-dev + ''; - meta = with lib; { - description = "Solana Platform Tools"; - homepage = "https://solana.com"; - platforms = platforms.linux; - }; -}) + meta = with lib; { + description = "Solana Platform Tools"; + homepage = "https://solana.com"; + platforms = platforms.aarch64 ++ platforms.unix; + }; + }) diff --git a/solana-rust.nix b/solana-rust.nix index 6985ccd..f82b0a5 100644 --- a/solana-rust.nix +++ b/solana-rust.nix @@ -1,30 +1,23 @@ -({ stdenv - , autoPatchelfHook - , lib - , solana-cli - , solana-platform-tools - }: -stdenv.mkDerivation rec { - pname = "solana-rust"; - version = solana-cli.version; +({ stdenv, autoPatchelfHook, lib, solana-cli, solana-platform-tools }: + stdenv.mkDerivation { + pname = "solana-rust"; + version = solana-cli.version; - phases = [ "installPhase" ]; - nativeBuildInputs = [ autoPatchelfHook ]; + phases = [ "installPhase" ]; + nativeBuildInputs = [ autoPatchelfHook ]; - buildInputs = [ - solana-platform-tools - ]; + buildInputs = [ solana-platform-tools ]; - installPhase = '' - mkdir -p $out/bin - rust=${solana-platform-tools}/bin/sdk/sbf/dependencies/platform-tools/rust/bin - ln -s $rust/cargo $out/bin/cargo - ln -s $rust/rustc $out/bin/rustc - ''; + installPhase = '' + mkdir -p $out/bin + rust=${solana-platform-tools}/bin/sdk/sbf/dependencies/platform-tools/rust/bin + ln -s $rust/cargo $out/bin/cargo + ln -s $rust/rustc $out/bin/rustc + ''; - meta = with lib; { - description = "Solana SDK"; - homepage = "https://solana.com"; - platforms = platforms.unix; - }; -}) + meta = with lib; { + description = "Solana SDK"; + homepage = "https://solana.com"; + platforms = platforms.unix; + }; + }) diff --git a/solana-source.nix b/solana-source.nix index 8afb4fb..4aa4364 100644 --- a/solana-source.nix +++ b/solana-source.nix @@ -1,11 +1,8 @@ -{ stdenv -, fetchFromGitHub -}: +{ stdenv, fetchFromGitHub }: let - version = "2.1.11"; - sha256 = "Wtc5+PkuZdicreImj9n0qqk6ZVwBZSlJytO1WTMoiMw="; -in -{ + version = "2.2.3"; + sha256 = "sha256-nRCamrwzoPX0cAEcP6p0t0t9Q41RjM6okupOPkJH5lQ="; +in { inherit version; src = fetchFromGitHub { owner = "anza-xyz";