···1+[workspace]
2+resolver = "2"
3+members = ["crates/*"]
4+5+6+[workspace.package]
7+authors = ["Orual <orual@nonbinary.computer>"]
8+edition = "2024"
9+description = "A simple Rust project using Nix"
10+version = "0.1.0"
11+12+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13+14+[workspace.dependencies]
15+clap = { version = "4.5", features = ["derive"] }
+21
LICENSE
···000000000000000000000
···1+MIT License
2+3+Copyright (c) 2023 Orual
4+5+Permission is hereby granted, free of charge, to any person obtaining a copy
6+of this software and associated documentation files (the "Software"), to deal
7+in the Software without restriction, including without limitation the rights
8+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+copies of the Software, and to permit persons to whom the Software is
10+furnished to do so, subject to the following conditions:
11+12+The above copyright notice and this permission notice shall be included in all
13+copies or substantial portions of the Software.
14+15+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+SOFTWARE.
···1+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).
2+3+> [!NOTE]
4+> 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/jacquard/tree/crate2nix). The evolution of this template can be gleaned from [releases](https://github.com/srid/jacquard/releases).
5+6+## Usage
7+8+You can use [omnix](https://omnix.page/om/init.html)[^omnix] to initialize this template:
9+```
10+nix run nixpkgs#omnix -- init github:srid/jacquard -o ~/my-rust-project
11+```
12+13+[^omnix]: If initializing manually, make sure to:
14+ - Change `name` in Cargo.toml.
15+ - Run `cargo generate-lockfile` in the nix shelld
16+17+## Adapting this template
18+19+- 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.
20+21+## Development (Flakes)
22+23+This repo uses [Flakes](https://nixos.asia/en/flakes) from the get-go.
24+25+```bash
26+# Dev shell
27+nix develop
28+29+# or run via cargo
30+nix develop -c cargo run
31+32+# build
33+nix build
34+```
35+36+We also provide a [`justfile`](https://just.systems/) for Makefile'esque commands to be run inside of the devShell.
37+38+## Tips
39+40+- Run `nix flake update` to update all flake inputs.
41+- Run `nix --accept-flake-config run github:juspay/omnix ci` to build _all_ outputs.
42+- [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.).
43+44+## Discussion
45+46+- [Zulip](https://nixos.zulipchat.com/#narrow/stream/413950-nix)
47+48+## See Also
49+50+- [nixos.wiki: Packaging Rust projects with nix](https://nixos.wiki/wiki/Rust#Packaging_Rust_projects_with_nix)
+11
crates/jacquard/Cargo.toml
···00000000000
···1+[package]
2+authors.workspace = true
3+# If you change the name here, you must also do it in flake.nix (and run `cargo generate-lockfile` afterwards)
4+name = "jacquard"
5+description = "A simple Rust project using Nix"
6+version.workspace = true
7+8+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9+10+[dependencies]
11+clap = { workspace = true }
+25
crates/jacquard/src/main.rs
···0000000000000000000000000
···1+use clap::Parser;
2+3+#[derive(Parser, Debug)]
4+#[command(author = "Orual", version, about)]
5+/// Application configuration
6+struct Args {
7+ /// whether to be verbose
8+ #[arg(short = 'v')]
9+ verbose: bool,
10+11+ /// an optional name to greet
12+ #[arg()]
13+ name: Option<String>,
14+}
15+16+fn main() {
17+ let args = Args::parse();
18+ if args.verbose {
19+ println!("DEBUG {args:?}");
20+ }
21+ println!(
22+ "Hello {} (from jacquard)!",
23+ args.name.unwrap_or("world".to_string())
24+ );
25+}
···1+default:
2+ @just --list
3+4+# Run pre-commit hooks on all files, including autoformatting
5+pre-commit-all:
6+ pre-commit run --all-files
7+8+# Run 'cargo run' on the project
9+run *ARGS:
10+ cargo run {{ARGS}}
11+12+# Run 'bacon' to run the project (auto-recompiles)
13+watch *ARGS:
14+ bacon --job run -- -- {{ ARGS }}