Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Nix build outputs
result*
.direnv/

# Development environments
.vscode/
.cursor/

# Rust/Cargo
target/
Cargo.lock
**/*.rs.bk
*.pdb

# macOS
.DS_Store
.AppleDouble
.LSOverride

# Temporary files
*.tmp
*.temp
*.log

# General
*.backup
*.bak
*.orig

# Working
work/
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Build Valence Contracts](./guides/build-valence-contracts.md)
- [Upload Contracts](./guides/upload-contracts.md)
- [ZK Development](./guides/zk-development.md)
- [Solana Development](./guides/solana-development.md)
- [Flake Modules Reference](./reference/flake-modules/index.md)
- [Upload Contracts Options](./reference/flake-modules/upload-contracts.md)
- [Valence Contracts Options](./reference/flake-modules/valence-contracts.md)
18 changes: 17 additions & 1 deletion docs/arch.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ The system includes packages for various blockchain-related tools:
- Manages specific contract packages for the Valence Protocol
- Supports multiple contract versions (v0.1.1, v0.1.2, and main)

- **Solana Tools** (`packages/solana-tools.nix`):
- Provides complete Solana development environment including CLI, Anchor framework, and platform tools
- Supports SBF (Solana Berkeley Format) program compilation
- Includes Solana CLI (v2.0.22), Anchor CLI (v0.31.1), and Platform Tools (v1.48)

### 3. Flake Modules

The flake modules extend the functionality of the system:
Expand All @@ -51,6 +56,15 @@ Additional tooling to support the blockchain simulation environment:
- Tools for building Valence Protocol contracts from source
- Integrates with the Rust toolchain via crane and rust-overlay

### 5. Templates

Development environment templates for different blockchain platforms:

- **Solana Development** (`templates/solana-development/`):
- Ready-to-use template for Solana development projects
- Includes complete Solana toolchain with Anchor framework
- Supports SBF program compilation and testing

## Architecture

```mermaid
Expand Down Expand Up @@ -260,4 +274,6 @@ Zero.nix can be used to simulate various multi-chain scenarios, such as:
- Validating IBC protocol implementations
- Developing and testing cross-chain applications
- Benchmarking relayer performance under different network conditions
- Simulating complex multi-chain application workflows
- Simulating complex multi-chain application workflows
- Developing Solana programs with SBF compilation support
- Testing Solana smart contracts using the Anchor framework
1 change: 1 addition & 0 deletions docs/guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
- [Build Valence Contracts](./build-valence-contracts.md)
- [Upload Contracts](./upload-contracts.md)
- [ZK Development](./zk-development.md)
- [Solana Development](./solana-development.md)

269 changes: 269 additions & 0 deletions docs/guides/solana-development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
# Solana Development

This document covers how to use zero.nix for Solana development, including setup of the Solana CLI, Anchor framework, and platform tools.

## Overview

Zero.nix provides a complete Solana development environment with:
- **Solana CLI** (v2.0.22) - Core Solana command-line tools
- **Anchor CLI** (v0.31.1) - Solana development framework
- **Platform Tools** (v1.48) - Rust compiler and LLVM tools optimized for Solana
- **SBF compilation** - Support for Solana Berkeley Format programs

## Quick Start

### Using the Template

Create a new Solana project using the zero.nix template:

```bash
nix flake new -t github:timewave-computer/zero.nix#solana-dev my-solana-project
cd my-solana-project
nix develop
```

### Manual Setup

Add zero.nix to your existing Solana project:

```nix
{
description = "My Solana project";

inputs = {
zero-nix.url = "github:timewave-computer/zero.nix";
};

outputs = { self, zero-nix }:
zero-nix.lib.mkFlake {
inherit self;
src = ./.;
};
}
```

## Development Environment

### Entering the Development Environment

```bash
nix develop
```

This provides access to:
- `solana` - Solana CLI tools
- `anchor` - Anchor framework CLI
- `cargo-build-sbf` - SBF program compilation
- `setup-solana` - Environment initialization script

### Environment Setup

Initialize the Solana development environment:

```bash
setup-solana
```

This script:
- Creates necessary cache directories
- Verifies platform tools installation
- Sets up proper permissions

## Working with Anchor

### Creating a New Anchor Project

```bash
anchor init my-project
cd my-project
```

### Building Anchor Programs

```bash
# Build the program
anchor build

# Build with SBF compilation
cargo-build-sbf
```

### Testing Anchor Programs

```bash
# Run tests
anchor test

# Run tests with local validator
anchor test --skip-local-validator
```

## Solana CLI Usage

### Configuration

```bash
# Configure Solana CLI for devnet
solana config set --url https://api.devnet.solana.com

# Generate a new keypair
solana-keygen new

# Check balance
solana balance
```

### Local Development

```bash
# Start local test validator
solana-test-validator

# Deploy to local cluster
solana program deploy target/deploy/my_program.so
```

## Platform Tools

The zero.nix Solana environment includes platform tools that provide:
- **Rust toolchain** - Optimized for Solana development
- **LLVM tools** - Required for SBF compilation
- **Cargo extensions** - SBF-specific build tools

### Platform Tools Environment

Platform tools are automatically configured with:
- `PLATFORM_TOOLS_DIR` - Points to platform tools directory
- `SBF_SDK_PATH` - SDK path for SBF compilation
- `PATH` - Extended to include platform tools

## SBF Program Development

### Building SBF Programs

```bash
# Build SBF programs directly
cargo-build-sbf --manifest-path=Cargo.toml

# Build with Anchor (recommended)
anchor build
```

### SBF Compilation Environment

The environment automatically configures:
- Rust toolchain compatible with Solana
- LLVM tools for SBF target compilation
- Proper linker settings for macOS

## Available Tools

### Core Tools

- **solana** - Main Solana CLI
- **solana-keygen** - Key generation and management
- **solana-test-validator** - Local test validator
- **anchor** - Anchor framework CLI
- **cargo-build-sbf** - SBF program compilation

### Development Tools

- **rustc** - Rust compiler
- **cargo** - Rust package manager
- **rust-analyzer** - Rust language server
- **nodejs** - JavaScript runtime
- **python3** - Python interpreter

## Configuration

### Environment Variables

The development environment automatically sets:

```bash
MACOSX_DEPLOYMENT_TARGET=11.0 # macOS deployment target
SOLANA_INSTALL_DIR=$HOME/.cache/solana # Solana cache directory
ANCHOR_VERSION=0.31.1 # Anchor version
SOLANA_VERSION=2.0.22 # Solana version
RUST_BACKTRACE=1 # Enable Rust backtraces
PLATFORM_TOOLS_DIR=<nix-store-path> # Platform tools directory (avoids redownloading)
SBF_SDK_PATH=<nix-store-path> # SBF SDK path for compilation
PROTOC=<nix-store-path>/bin/protoc # Protocol buffers compiler
CARGO_HOME=$HOME/.cache/solana/v1.48/cargo # Cargo cache directory (prevents redownloading)
RUSTUP_HOME=$HOME/.cache/solana/v1.48/rustup # Rustup cache directory (prevents redownloading)
```

These environment variables ensure that:
- Platform tools are not redownloaded on each build
- SBF compilation uses the pre-installed tools
- Proper macOS deployment target is set
- Debugging information is available
- Cargo and rustup use cached platform tools configuration

### Custom Configuration

Extend the development environment in your `flake.nix`:

```nix
{
outputs = { self, zero-nix }:
zero-nix.lib.mkFlake {
inherit self;
src = ./.;

devShells.default = zero-nix.devShells.default.overrideAttrs (oldAttrs: {
shellHook = (oldAttrs.shellHook or "") + ''
# Custom solana configuration
solana config set --url https://api.mainnet-beta.solana.com

# Project-specific setup
echo "My Solana project initialized"
'';
});
};
}
```

### Debug Mode

Enable verbose output for debugging:

```bash
RUST_BACKTRACE=full anchor build
```

## Integration with Existing Projects

### Adding to Existing Rust Projects

Add zero.nix to your `flake.nix`:

```nix
{
inputs = {
zero-nix.url = "github:timewave-computer/zero.nix";
};

outputs = { self, zero-nix }: {
devShells.default = zero-nix.devShells.default.overrideAttrs (oldAttrs: {
buildInputs = (oldAttrs.buildInputs or []) ++ (with zero-nix.legacyPackages.${system}; [
solana-tools
# Add your existing tools here
]);
});
};
}
```

## Documentation

- [Anchor Book](https://book.anchor-lang.com/)
- [Solana program development](https://docs.solana.com/developing/programming-model/overview)
- [Solana CLI reference](https://docs.solana.com/cli)

## Version Information

- **Solana CLI**: v2.0.22
- **Anchor CLI**: v0.31.1
- **Platform Tools**: v1.48
- **Rust**: Compatible with Solana (via platform tools)
Loading
Loading