At the core, we use Nix, an advanced package manager, to set up a reliable and reproducible development shell specifically for Rust projects. This ensures that you work in a controlled environment with consistent dependencies and tooling.
- divnix - Standard: Used to maintain organization and clarity in your Nix code. It helps in keeping the structure of your Nix configurations neat and readable.
- Fenix: Responsible for fetching the latest Rust binaries through Nix. This ensures that you always have access to the newest features and updates in Rust.
- Crane: A tool that enhances the building process of Rust projects within Nix. It allows for incremental builds, significantly speeding up the development cycle and facilitating rapid iteration.
- Rust Analyzer Integration: We've seamlessly integrated Rust Analyzer to work out-of-the-box. This is particularly beneficial for terminal-based editors supporting language servers, offering immediate and efficient code analysis.
- Editor Recommendation: For an editor with exceptional support for both Nix and Rust, we recommend trying out Helix . It's configured to work smoothly with this setup, providing an enriched coding experience.
Follow these steps to set up a new Rust project using this template:
# Create a new empty project directory
mkdir my-project
cd my-project
# Initialize the project with this template
nix flake init -t github:moon0440/nix-flake-rust
# Initialize Git and Cargo, and perform initial build
git init
cargo init # Use --lib for library projects
cargo build # Generates Cargo.lock
git add .
git commit -m "Initial project setup"
# Enter the development shell
direnv allow || nix develop
By following these steps, you'll have a Rust project environment ready, complete with all the necessary tools and configurations for an efficient and organized development process.
- divnix - Standard (std): GitHub - divnix/std
- Nix: NixOS - Nix
- Flakes: NixOS - Flakes
- Fenix: GitHub - nix-community/fenix
- Crane: GitHub - ipetkov/crane
- Helix Editor: GitHub - helix-editor/helix