Skip to content
/ nix-rust-template Public template

A reasonable way to start developing a reproducible Rust project

License

Notifications You must be signed in to change notification settings

rpearce/nix-rust-template

Repository files navigation

nix-rust-template

A reasonable way to start developing a reproducible Rust project.

This reproducibility is enabled by Nix and Docker.

Features

This is a template repository; everything is customizable, and some helpful defaults are included.

  • Default rust extensions:
    • clippy-preview: A collection of lints to catch common mistakes and improve your Rust code
    • rust-src
    • rustc-dev
    • rustfmt: A tool for formatting Rust code according to style guidelines
  • Default dev tools:
    • rust-analyzer: Excellent IDE support
    • cargo-watch: Watches over your project's source for changes, and runs Cargo commands when they occur
    • cargo-edit: Extends Cargo to allow you to add, remove, and upgrade dependencies by modifying your Cargo.toml file from the command line
  • naersk: Nix support for building cargo crates
  • oxalica/rust-overlay: Pure and reproducible overlay for binary distributed rust toolchains

Setup

With Docker

With docker compose (recommended)

docker compose build
docker compose up

Without docker compose

docker build . -t nix-rust-template
docker volume create nix-rust-template-vol
docker run --rm -it -v $PWD:/service nix-rust-template:latest

Without Docker

  1. Install nix
  2. Install nix flakes

Commands

If you are using Docker, prefix the following with docker compose run --rm app; for example:

docker compose run --rm app nix run .#watch
  • nix build: build the package
  • nix run or nix run .#app: run the package
  • nix run .#watch: watch the package for changes and rerun
  • nix develop: enter a reproducible rust shell environment
    • How to watch for changes and rerun:
      cargo watch -w "./src/" -x "run"