Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/srid/rust-nix-template
Rust project template with Nix (Flakes) and VSCode support
https://github.com/srid/rust-nix-template
nix rust template-project vscode
Last synced: 3 days ago
JSON representation
Rust project template with Nix (Flakes) and VSCode support
- Host: GitHub
- URL: https://github.com/srid/rust-nix-template
- Owner: srid
- License: mit
- Created: 2021-04-06T17:28:17.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-17T13:27:25.000Z (4 months ago)
- Last Synced: 2024-10-19T18:54:56.683Z (4 months ago)
- Topics: nix, rust, template-project, vscode
- Language: Nix
- Homepage: https://srid.ca/rust-nix
- Size: 111 KB
- Stars: 206
- Watchers: 3
- Forks: 21
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A template Rust project with fully functional and no-frills Nix support, as well as builtin VSCode configuration to get IDE experience without any manual setup (just [install direnv](https://nixos.asia/en/direnv), open in VSCode and accept the suggestions). It uses [crane](https://crane.dev/), via [rust-flake](https://github.com/juspay/rust-flake).
> [!NOTE]
> If you are looking for the original template based on [this blog post](https://srid.ca/rust-nix)'s use of `crate2nix`, browse from [this tag](https://github.com/srid/rust-nix-template/tree/crate2nix). The evolution of this template can be gleaned from [releases](https://github.com/srid/rust-nix-template/releases).## Usage
You can use [omnix](https://omnix.page/om/init.html)[^omnix] to initialize this template:
```
nix --accept-flake-config run github:juspay/omnix -- init github:srid/rust-nix-template -o ~/my-rust-project
```[^omnix]: If initializing manually, make sure to:
- Change `name` in Cargo.toml.
- Run `cargo generate-lockfile` in the nix shelld## Adapting this template
- There are two CI workflows, and one of them uses Nix which is slower (unless you configure a cache) than the other one based on rustup. Pick one or the other depending on your trade-offs.
## Development (Flakes)
This repo uses [Flakes](https://nixos.asia/en/flakes) from the get-go.
```bash
# Dev shell
nix develop# or run via cargo
nix develop -c cargo run# build
nix build
```We also provide a [`justfile`](https://just.systems/) for Makefile'esque commands to be run inside of the devShell.
## Tips
- Run `nix flake update` to update all flake inputs.
- Run `nix --accept-flake-config run github:juspay/omnix ci` to build _all_ outputs.
- [pre-commit] hooks will automatically be setup in Nix shell. You can also run `pre-commit run -a` manually to run the hooks (e.g.: to autoformat the project tree using `rustfmt`, `nixpkgs-fmt`, etc.).## Discussion
- [Zulip](https://nixos.zulipchat.com/#narrow/stream/413950-nix)
## See Also
- [nixos.wiki: Packaging Rust projects with nix](https://nixos.wiki/wiki/Rust#Packaging_Rust_projects_with_nix)