···11+[workspace]
22+resolver = "2"
33+members = ["crates/*"]
44+55+66+[workspace.package]
77+authors = ["Orual <orual@nonbinary.computer>"]
88+edition = "2024"
99+description = "A simple Rust project using Nix"
1010+version = "0.1.0"
1111+1212+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313+1414+[workspace.dependencies]
1515+clap = { version = "4.5", features = ["derive"] }
+21
LICENSE
···11+MIT License
22+33+Copyright (c) 2023 Orual
44+55+Permission is hereby granted, free of charge, to any person obtaining a copy
66+of this software and associated documentation files (the "Software"), to deal
77+in the Software without restriction, including without limitation the rights
88+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+copies of the Software, and to permit persons to whom the Software is
1010+furnished to do so, subject to the following conditions:
1111+1212+The above copyright notice and this permission notice shall be included in all
1313+copies or substantial portions of the Software.
1414+1515+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+SOFTWARE.
+50
README.md
···11+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).
22+33+> [!NOTE]
44+> 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).
55+66+## Usage
77+88+You can use [omnix](https://omnix.page/om/init.html)[^omnix] to initialize this template:
99+```
1010+nix run nixpkgs#omnix -- init github:srid/jacquard -o ~/my-rust-project
1111+```
1212+1313+[^omnix]: If initializing manually, make sure to:
1414+ - Change `name` in Cargo.toml.
1515+ - Run `cargo generate-lockfile` in the nix shelld
1616+1717+## Adapting this template
1818+1919+- 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.
2020+2121+## Development (Flakes)
2222+2323+This repo uses [Flakes](https://nixos.asia/en/flakes) from the get-go.
2424+2525+```bash
2626+# Dev shell
2727+nix develop
2828+2929+# or run via cargo
3030+nix develop -c cargo run
3131+3232+# build
3333+nix build
3434+```
3535+3636+We also provide a [`justfile`](https://just.systems/) for Makefile'esque commands to be run inside of the devShell.
3737+3838+## Tips
3939+4040+- Run `nix flake update` to update all flake inputs.
4141+- Run `nix --accept-flake-config run github:juspay/omnix ci` to build _all_ outputs.
4242+- [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.).
4343+4444+## Discussion
4545+4646+- [Zulip](https://nixos.zulipchat.com/#narrow/stream/413950-nix)
4747+4848+## See Also
4949+5050+- [nixos.wiki: Packaging Rust projects with nix](https://nixos.wiki/wiki/Rust#Packaging_Rust_projects_with_nix)
+11
crates/jacquard/Cargo.toml
···11+[package]
22+authors.workspace = true
33+# If you change the name here, you must also do it in flake.nix (and run `cargo generate-lockfile` afterwards)
44+name = "jacquard"
55+description = "A simple Rust project using Nix"
66+version.workspace = true
77+88+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99+1010+[dependencies]
1111+clap = { workspace = true }
+25
crates/jacquard/src/main.rs
···11+use clap::Parser;
22+33+#[derive(Parser, Debug)]
44+#[command(author = "Orual", version, about)]
55+/// Application configuration
66+struct Args {
77+ /// whether to be verbose
88+ #[arg(short = 'v')]
99+ verbose: bool,
1010+1111+ /// an optional name to greet
1212+ #[arg()]
1313+ name: Option<String>,
1414+}
1515+1616+fn main() {
1717+ let args = Args::parse();
1818+ if args.verbose {
1919+ println!("DEBUG {args:?}");
2020+ }
2121+ println!(
2222+ "Hello {} (from jacquard)!",
2323+ args.name.unwrap_or("world".to_string())
2424+ );
2525+}
···11+default:
22+ @just --list
33+44+# Run pre-commit hooks on all files, including autoformatting
55+pre-commit-all:
66+ pre-commit run --all-files
77+88+# Run 'cargo run' on the project
99+run *ARGS:
1010+ cargo run {{ARGS}}
1111+1212+# Run 'bacon' to run the project (auto-recompiles)
1313+watch *ARGS:
1414+ bacon --job run -- -- {{ ARGS }}