This guide will help you set up the development environment for template-rust using various methods.
Choose one of the following setup methods based on your preference:
- Local Development: Rust 1.70+, SQLite3
- Docker: Docker 20.10+ and Docker Compose (optional)
- Nix: Nix package manager with flakes enabled
- Codespaces: GitHub account (no local setup required)
The fastest way to get started depends on your environment:
# Local development
cargo run -- --help
# Docker
docker compose up
# Nix (with flakes)
nix develop
cargo run
# GitHub Codespaces
# Just open the repository in Codespaces - everything is preconfigured!-
Install Rust (if not already installed):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source $HOME/.cargo/env
-
Install SQLite (if not already installed):
-
Ubuntu/Debian:
sudo apt-get update sudo apt-get install sqlite3 libsqlite3-dev
-
macOS:
brew install sqlite
-
Windows: Download from SQLite Download Page
-
-
Clone and build:
git clone https://github.com/pnstack/template-rust.git cd template-rust cargo build --release -
Run the application:
cargo run -- --help
Install additional development tools:
# Format checker
rustup component add rustfmt
# Linter
rustup component add clippy
# IDE support
rustup component add rust-analyzer-
Build the Docker image:
docker build -t template-rust:latest . -
Run the container:
# Run with help docker run --rm template-rust:latest --help # Run TUI mode (interactive) docker run --rm -it -v $(pwd)/data:/app/data template-rust:latest tui # Run CLI commands docker run --rm -v $(pwd)/data:/app/data template-rust:latest list
-
Persist data:
The container stores data in
/app/data. Mount a volume to persist data:mkdir -p data docker run --rm -it -v $(pwd)/data:/app/data template-rust:latest tui
Docker Compose simplifies multi-service development and provides predefined configurations.
-
Start the application:
docker compose up template-rust
-
Start in development mode:
# Development mode with live code mounting docker compose up dev -
Build and run:
docker compose up --build
-
Run in detached mode:
docker compose up -d
-
Stop services:
docker compose down
The dev service in docker-compose.yml provides:
- Live code mounting for rapid development
- Cargo cache for faster builds
- Interactive terminal access
# Enter development container
docker compose run --rm dev bash
# Inside container
cargo build
cargo test
cargo run -- tuiNix provides reproducible development environments across different systems.
-
Enable flakes (if not already enabled):
mkdir -p ~/.config/nix echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
-
Enter development environment:
nix develop
This provides:
- Rust toolchain with rust-analyzer
- All build dependencies
- Development tools
-
Build the project:
nix build
-
Run the application:
nix run
If you prefer not to use flakes:
nix-shellThis provides the same development environment using shell.nix.
For automatic environment activation:
-
Install direnv:
# Via Nix nix-env -iA nixpkgs.direnv # Via package manager # Ubuntu/Debian: sudo apt install direnv # macOS: brew install direnv
-
Configure direnv:
# Add to ~/.bashrc or ~/.zshrc eval "$(direnv hook bash)" # or zsh
-
Create .envrc:
echo "use flake" > .envrc direnv allow
Now the environment activates automatically when you enter the directory!
The easiest way to get started with zero local setup.
-
Open in Codespaces:
- Navigate to the repository on GitHub
- Click "Code" → "Codespaces" → "Create codespace on main"
- Wait for the environment to build (first time only)
-
Start developing:
- All tools are pre-installed
- VS Code with Rust extensions ready
- Project automatically builds on creation
If you have Docker and VS Code locally:
-
Install prerequisites:
- Docker Desktop
- VS Code
- "Dev Containers" extension for VS Code
-
Open in container:
- Open the repository in VS Code
- Press
F1→ "Dev Containers: Reopen in Container" - Wait for container to build
-
Start developing:
- Integrated terminal has all tools
- Extensions auto-installed
- Same environment as Codespaces
cargo buildcargo build --releaseThe binary will be in target/release/template-rust.
cargo checkcargo testcargo test test_namecargo test -- --nocapturecargo test --test integration_testscargo fmtcargo fmt --checkcargo clippycargo clippy -- -D warningsSolution: Install SQLite development libraries
# Ubuntu/Debian
sudo apt-get install libsqlite3-dev
# macOS
brew install sqlite
# Nix
nix develop # Automatically provides SQLiteSolution: Install OpenSSL development libraries
# Ubuntu/Debian
sudo apt-get install libssl-dev pkg-config
# macOS
brew install openssl
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
# Nix
nix develop # Automatically provides OpenSSLSolution: This is normal - Cargo downloads and compiles all dependencies on first build. Subsequent builds are much faster due to caching.
For Docker users, the multi-stage build and layer caching help reduce rebuild times.
Solution: The container runs as non-root user. Ensure mounted volumes have appropriate permissions:
mkdir -p data
chmod 777 data # Or use appropriate user/group ownershipSolution: Close any other instances of the application accessing the same database file, or use a different database path:
./template-rust --database another.db tuiThe application supports the following environment variables:
DATABASE_URL: Path to the SQLite database file (default:todo.db)RUST_BACKTRACE: Set to1orfullfor detailed error tracesRUST_LOG: Set log level (e.g.,debug,info,warn,error)
Example:
export DATABASE_URL=":memory:" # Use in-memory database
export RUST_BACKTRACE=1 # Enable backtraces
cargo runAfter setting up your environment:
- Read the README.md for usage instructions
- Explore the examples/ directory
- Check the tests/ directory for test examples
- Review the CI/CD workflows to understand the automation
If you encounter issues:
- Check this guide's Common Issues section
- Search existing GitHub Issues
- Open a new issue with:
- Your setup method (Local/Docker/Nix/Codespaces)
- Operating system and version
- Rust version (
rustc --version) - Complete error message
- Steps to reproduce
See README.md for contribution guidelines.