Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 83 additions & 51 deletions anchor-cli.nix
Original file line number Diff line number Diff line change
@@ -1,65 +1,97 @@
{ stdenv
, darwin
, fetchFromGitHub
, lib
, libgcc
, pkg-config
, protobuf
, makeRustPlatform
, makeWrapper
, solana-platform-tools
, rust-bin
, udev
}:
let
# 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.85.0".default;
rustc = rust-bin.stable."1.85.0".default;
};
in
rustPlatform.buildRustPackage rec {
{
stdenv,
darwin,
fetchFromGitHub,
lib,
pkg-config,
protobuf,
makeWrapper,
solana-platform-tools,
rust-bin,
udev,
crane,
version ? "0.31.0",
}: let
pname = "anchor-cli";
version = "0.31.0";

doCheck = false;
versionsDeps = {
"0.31.0" = {
hash = "sha256-CaBVdp7RPVmzzEiVazjpDLJxEkIgy1BHCwdH2mYLbGM=";
rust = rust-bin.stable."1.85.0".default;
platform-tools = solana-platform-tools.override {version = "1.45";};
patches = [./patches/anchor-cli/0.31.0.patch];
};
"0.30.1" = {
hash = "sha256-3fLYTJDVCJdi6o0Zd+hb9jcPDKm4M4NzpZ8EUVW/GVw=";
rust = rust-bin.stable."1.78.0".default;
platform-tools = solana-platform-tools.override {version = "1.43";};
patches = [./patches/anchor-cli/0.30.1.patch];
};
};
versionDeps = versionsDeps.${version};

nativeBuildInputs = [ protobuf pkg-config makeWrapper ];
buildInputs = [ ]
++ lib.optionals stdenv.isLinux [ udev ]
++ lib.optional
stdenv.isDarwin [
darwin.apple_sdk.frameworks.CoreFoundation
];
craneLib =
crane.overrideToolchain
versionDeps.rust;

src = fetchFromGitHub {
originalSrc = fetchFromGitHub {
owner = "coral-xyz";
repo = "anchor";
rev = "v${version}";
hash = "sha256-CaBVdp7RPVmzzEiVazjpDLJxEkIgy1BHCwdH2mYLbGM=";
hash = versionDeps.hash;
};

cargoLock = {
lockFile = "${src.outPath}/Cargo.lock";
allowBuiltinFetchGit = true;
};
src = stdenv.mkDerivation {
name = "anchor-cli-patched";
src = originalSrc;

# Apply the patch
phases = ["unpackPhase" "patchPhase" "installPhase"];
patches = versionDeps.patches;

patches = [
./anchor-cli.patch
];
# Install the patched source as an output
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r ./* $out/
runHook postInstall
'';
};

# Ensure anchor has access to Solana's cargo and rust binaries
postInstall = ''
rust=${solana-platform-tools}/bin/platform-tools-sdk/sbf/dependencies/platform-tools/rust/bin
wrapProgram $out/bin/anchor \
--prefix PATH : "$rust"
'';
commonArgs = {
inherit pname version src;

buildAndTestSubdir = "cli";
strictDeps = true;
doCheck = false;

meta = {
description = "Anchor cli";
nativeBuildInputs = [protobuf pkg-config makeWrapper];
buildInputs =
[]
++ lib.optionals stdenv.isLinux [udev]
++ lib.optional stdenv.isDarwin
[darwin.apple_sdk.frameworks.CoreFoundation];
};
}

cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;

# Ensure anchor has access to Solana's cargo and rust binaries
postInstall = ''
rust=${versionDeps.platform-tools}/bin/platform-tools-sdk/sbf/dependencies/platform-tools/rust/bin
wrapProgram $out/bin/anchor \
--prefix PATH : "$rust"
'';

cargoExtraArgs = "-p ${pname}";

meta = {
description = "Anchor cli";
};

passthru = {
otherVersions = builtins.attrNames versionsDeps;
};
})
7 changes: 1 addition & 6 deletions criterion.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{ lib
, fetchFromGitHub
, cmake
, pkg-config
, criterion
}:
{ lib, fetchFromGitHub, cmake, pkg-config, criterion }:
Comment thread
Karrq marked this conversation as resolved.
Outdated
criterion.overrideAttrs rec {
version = "2.3.3";

Expand Down
114 changes: 114 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
description = "Solana development setup with Nix.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/c5e2528c7c4ec05ce05a563e3be64f3525b278ad";
Comment thread
Karrq marked this conversation as resolved.
Outdated
flake-parts.url = "github:hercules-ci/flake-parts/f4330d22f1c5d2ba72d3d22df5597d123fdb60a9";
rust-overlay.url = "github:oxalica/rust-overlay/87f0965f9f5b13fca9f38074eee8369dc767550d";
crane.url = "github:ipetkov/crane";
};
outputs = inputs @ {
self,
nixpkgs,
flake-parts,
rust-overlay,
crane,
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
"x86_64-windows"
Comment thread
Karrq marked this conversation as resolved.
];
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;
crane = crane.mkLib pkgs;
};
anchor-cli = callPackage (import ./anchor-cli.nix) {
inherit solana-platform-tools;
crane = crane.mkLib pkgs;
};
in {
devShells.default = mkShell {
packages = [anchor-cli solana-cli solana-rust yarn nodejs];
};

packages = {inherit anchor-cli solana-cli solana-platform-tools solana-rust;};
};
};
}
Loading