A better Rust ATProto crate

init

Orual 4ae6df30

+8
.envrc
···
+
if ! has nix_direnv_version || ! nix_direnv_version 3.1.0; then
+
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.1.0/direnvrc" "sha256-yMJ2OVMzrFaDPn7q8nCBZFRYpL/f0RcHzhmw/i6btJM="
+
fi
+
+
watch_file \
+
rust-toolchain.toml \
+
nix/modules/*.nix
+
use flake
+1
.gitattributes
···
+
flake.lock linguist-generated=true
+19
.github/workflows/ci-nix.yml
···
+
name: "CI Nix"
+
on:
+
# Run only when pushing to master branch, and making PRs
+
push:
+
branches:
+
- master
+
pull_request:
+
jobs:
+
build:
+
runs-on: ${{ matrix.os }}
+
strategy:
+
matrix:
+
os: [ubuntu-latest, macos-14]
+
steps:
+
- uses: actions/checkout@v4
+
- uses: nixbuild/nix-quick-install-action@v33
+
- name: Install omnix
+
run: nix --accept-flake-config profile install "github:juspay/omnix"
+
- run: om ci
+24
.github/workflows/ci.yml
···
+
on: [push]
+
+
name: CI
+
+
jobs:
+
check:
+
name: Rust project
+
runs-on: ubuntu-latest
+
steps:
+
- uses: actions/checkout@v2
+
- name: Install latest nightly
+
uses: actions-rs/toolchain@v1
+
with:
+
toolchain: nightly
+
override: true
+
components: rustfmt, clippy
+
+
# `cargo check` command here will use installed `nightly`
+
# as it is set as an "override" for current directory
+
+
- name: Run cargo check
+
uses: actions-rs/cargo@v1
+
with:
+
command: check
+6
.gitignore
···
+
/target
+
/result
+
/result-lib
+
.direnv
+
+
/.pre-commit-config.yaml
+9
.vscode/extensions.json
···
+
{
+
"recommendations": [
+
"rust-lang.rust-analyzer",
+
"jnoortheen.nix-ide",
+
"mkhl.direnv",
+
"tamasfe.even-better-toml",
+
"fill-labs.dependi"
+
]
+
}
+8
.vscode/settings.json
···
+
{
+
"editor.formatOnSave": true,
+
"rust-analyzer.files.excludeDirs": [
+
".direnv"
+
],
+
// https://twitter.com/sridca/status/1674947342607216641
+
// "editor.inlayHints.enabled": "offUnlessPressed",
+
}
+251
Cargo.lock
···
+
# This file is automatically @generated by Cargo.
+
# It is not intended for manual editing.
+
version = 4
+
+
[[package]]
+
name = "anstream"
+
version = "0.6.20"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192"
+
dependencies = [
+
"anstyle",
+
"anstyle-parse",
+
"anstyle-query",
+
"anstyle-wincon",
+
"colorchoice",
+
"is_terminal_polyfill",
+
"utf8parse",
+
]
+
+
[[package]]
+
name = "anstyle"
+
version = "1.0.11"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
+
+
[[package]]
+
name = "anstyle-parse"
+
version = "0.2.7"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
+
dependencies = [
+
"utf8parse",
+
]
+
+
[[package]]
+
name = "anstyle-query"
+
version = "1.1.4"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
+
dependencies = [
+
"windows-sys",
+
]
+
+
[[package]]
+
name = "anstyle-wincon"
+
version = "3.0.10"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
+
dependencies = [
+
"anstyle",
+
"once_cell_polyfill",
+
"windows-sys",
+
]
+
+
[[package]]
+
name = "clap"
+
version = "4.5.48"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae"
+
dependencies = [
+
"clap_builder",
+
"clap_derive",
+
]
+
+
[[package]]
+
name = "clap_builder"
+
version = "4.5.48"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9"
+
dependencies = [
+
"anstream",
+
"anstyle",
+
"clap_lex",
+
"strsim",
+
]
+
+
[[package]]
+
name = "clap_derive"
+
version = "4.5.47"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c"
+
dependencies = [
+
"heck",
+
"proc-macro2",
+
"quote",
+
"syn",
+
]
+
+
[[package]]
+
name = "clap_lex"
+
version = "0.7.5"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
+
+
[[package]]
+
name = "colorchoice"
+
version = "1.0.4"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
+
+
[[package]]
+
name = "heck"
+
version = "0.5.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
+
+
[[package]]
+
name = "is_terminal_polyfill"
+
version = "1.70.1"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
+
+
[[package]]
+
name = "jacquard"
+
version = "0.1.0"
+
dependencies = [
+
"clap",
+
]
+
+
[[package]]
+
name = "once_cell_polyfill"
+
version = "1.70.1"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
+
+
[[package]]
+
name = "proc-macro2"
+
version = "1.0.101"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
+
dependencies = [
+
"unicode-ident",
+
]
+
+
[[package]]
+
name = "quote"
+
version = "1.0.40"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
+
dependencies = [
+
"proc-macro2",
+
]
+
+
[[package]]
+
name = "strsim"
+
version = "0.11.1"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
+
+
[[package]]
+
name = "syn"
+
version = "2.0.106"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
+
dependencies = [
+
"proc-macro2",
+
"quote",
+
"unicode-ident",
+
]
+
+
[[package]]
+
name = "unicode-ident"
+
version = "1.0.19"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
+
+
[[package]]
+
name = "utf8parse"
+
version = "0.2.2"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
+
+
[[package]]
+
name = "windows-link"
+
version = "0.2.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65"
+
+
[[package]]
+
name = "windows-sys"
+
version = "0.60.2"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
+
dependencies = [
+
"windows-targets",
+
]
+
+
[[package]]
+
name = "windows-targets"
+
version = "0.53.4"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "2d42b7b7f66d2a06854650af09cfdf8713e427a439c97ad65a6375318033ac4b"
+
dependencies = [
+
"windows-link",
+
"windows_aarch64_gnullvm",
+
"windows_aarch64_msvc",
+
"windows_i686_gnu",
+
"windows_i686_gnullvm",
+
"windows_i686_msvc",
+
"windows_x86_64_gnu",
+
"windows_x86_64_gnullvm",
+
"windows_x86_64_msvc",
+
]
+
+
[[package]]
+
name = "windows_aarch64_gnullvm"
+
version = "0.53.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
+
+
[[package]]
+
name = "windows_aarch64_msvc"
+
version = "0.53.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
+
+
[[package]]
+
name = "windows_i686_gnu"
+
version = "0.53.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
+
+
[[package]]
+
name = "windows_i686_gnullvm"
+
version = "0.53.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
+
+
[[package]]
+
name = "windows_i686_msvc"
+
version = "0.53.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
+
+
[[package]]
+
name = "windows_x86_64_gnu"
+
version = "0.53.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
+
+
[[package]]
+
name = "windows_x86_64_gnullvm"
+
version = "0.53.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
+
+
[[package]]
+
name = "windows_x86_64_msvc"
+
version = "0.53.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
+15
Cargo.toml
···
+
[workspace]
+
resolver = "2"
+
members = ["crates/*"]
+
+
+
[workspace.package]
+
authors = ["Orual <orual@nonbinary.computer>"]
+
edition = "2024"
+
description = "A simple Rust project using Nix"
+
version = "0.1.0"
+
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+
[workspace.dependencies]
+
clap = { version = "4.5", features = ["derive"] }
+21
LICENSE
···
+
MIT License
+
+
Copyright (c) 2023 Orual
+
+
Permission is hereby granted, free of charge, to any person obtaining a copy
+
of this software and associated documentation files (the "Software"), to deal
+
in the Software without restriction, including without limitation the rights
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+
copies of the Software, and to permit persons to whom the Software is
+
furnished to do so, subject to the following conditions:
+
+
The above copyright notice and this permission notice shall be included in all
+
copies or substantial portions of the Software.
+
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+
SOFTWARE.
+50
README.md
···
+
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/jacquard/tree/crate2nix). The evolution of this template can be gleaned from [releases](https://github.com/srid/jacquard/releases).
+
+
## Usage
+
+
You can use [omnix](https://omnix.page/om/init.html)[^omnix] to initialize this template:
+
```
+
nix run nixpkgs#omnix -- init github:srid/jacquard -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)
+11
crates/jacquard/Cargo.toml
···
+
[package]
+
authors.workspace = true
+
# If you change the name here, you must also do it in flake.nix (and run `cargo generate-lockfile` afterwards)
+
name = "jacquard"
+
description = "A simple Rust project using Nix"
+
version.workspace = true
+
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+
[dependencies]
+
clap = { workspace = true }
+25
crates/jacquard/src/main.rs
···
+
use clap::Parser;
+
+
#[derive(Parser, Debug)]
+
#[command(author = "Orual", version, about)]
+
/// Application configuration
+
struct Args {
+
/// whether to be verbose
+
#[arg(short = 'v')]
+
verbose: bool,
+
+
/// an optional name to greet
+
#[arg()]
+
name: Option<String>,
+
}
+
+
fn main() {
+
let args = Args::parse();
+
if args.verbose {
+
println!("DEBUG {args:?}");
+
}
+
println!(
+
"Hello {} (from jacquard)!",
+
args.name.unwrap_or("world".to_string())
+
);
+
}
+172
flake.lock
···
+
{
+
"nodes": {
+
"cargo-doc-live": {
+
"locked": {
+
"lastModified": 1724704668,
+
"narHash": "sha256-kJFYXlWUodg5WhJ0NuvrP0mCvOT/2AOIo8oGeYLXocs=",
+
"owner": "srid",
+
"repo": "cargo-doc-live",
+
"rev": "b09d5d258d2498829e03014931fc19aed499b86f",
+
"type": "github"
+
},
+
"original": {
+
"owner": "srid",
+
"repo": "cargo-doc-live",
+
"type": "github"
+
}
+
},
+
"crane": {
+
"locked": {
+
"lastModified": 1736566337,
+
"narHash": "sha256-SC0eDcZPqISVt6R0UfGPyQLrI0+BppjjtQ3wcSlk0oI=",
+
"owner": "ipetkov",
+
"repo": "crane",
+
"rev": "9172acc1ee6c7e1cbafc3044ff850c568c75a5a3",
+
"type": "github"
+
},
+
"original": {
+
"owner": "ipetkov",
+
"repo": "crane",
+
"type": "github"
+
}
+
},
+
"flake-parts": {
+
"inputs": {
+
"nixpkgs-lib": [
+
"nixpkgs"
+
]
+
},
+
"locked": {
+
"lastModified": 1725234343,
+
"narHash": "sha256-+ebgonl3NbiKD2UD0x4BszCZQ6sTfL4xioaM49o5B3Y=",
+
"owner": "hercules-ci",
+
"repo": "flake-parts",
+
"rev": "567b938d64d4b4112ee253b9274472dc3a346eb6",
+
"type": "github"
+
},
+
"original": {
+
"owner": "hercules-ci",
+
"repo": "flake-parts",
+
"type": "github"
+
}
+
},
+
"git-hooks": {
+
"flake": false,
+
"locked": {
+
"lastModified": 1734425854,
+
"narHash": "sha256-nzE5UbJ41aPEKf8R2ZFYtLkqPmF7EIUbNEdHMBLg0Ig=",
+
"owner": "cachix",
+
"repo": "git-hooks.nix",
+
"rev": "0ddd26d0925f618c3a5d85a4fa5eb1e23a09491d",
+
"type": "github"
+
},
+
"original": {
+
"owner": "cachix",
+
"repo": "git-hooks.nix",
+
"type": "github"
+
}
+
},
+
"nixpkgs": {
+
"locked": {
+
"lastModified": 1736693123,
+
"narHash": "sha256-9lIfXCaBPwUA7FnfDnoH4gxxdOvXG78k6UlUw0+ZDxc=",
+
"owner": "nixos",
+
"repo": "nixpkgs",
+
"rev": "2fdec2c2e68b7b7845d1ea4e0894c63143e3261b",
+
"type": "github"
+
},
+
"original": {
+
"owner": "nixos",
+
"ref": "nixpkgs-unstable",
+
"repo": "nixpkgs",
+
"type": "github"
+
}
+
},
+
"process-compose-flake": {
+
"locked": {
+
"lastModified": 1724606023,
+
"narHash": "sha256-rdGeNa/lCS8E1lXzPqgl+vZUUvnbEZT11Bqkx5jfYug=",
+
"owner": "Platonic-Systems",
+
"repo": "process-compose-flake",
+
"rev": "f6ce9481df9aec739e4e06b67492401a5bb4f0b1",
+
"type": "github"
+
},
+
"original": {
+
"owner": "Platonic-Systems",
+
"repo": "process-compose-flake",
+
"type": "github"
+
}
+
},
+
"root": {
+
"inputs": {
+
"cargo-doc-live": "cargo-doc-live",
+
"flake-parts": "flake-parts",
+
"git-hooks": "git-hooks",
+
"nixpkgs": "nixpkgs",
+
"process-compose-flake": "process-compose-flake",
+
"rust-flake": "rust-flake",
+
"systems": "systems"
+
}
+
},
+
"rust-flake": {
+
"inputs": {
+
"crane": "crane",
+
"nixpkgs": [
+
"nixpkgs"
+
],
+
"rust-overlay": "rust-overlay"
+
},
+
"locked": {
+
"lastModified": 1736806612,
+
"narHash": "sha256-WioA+Vk7suDK+Ek77rDlbuxV6WqwFt30JsKHrmDCSiU=",
+
"owner": "juspay",
+
"repo": "rust-flake",
+
"rev": "b5f39885e2fcf137bfaf75decc077f9cca2bd984",
+
"type": "github"
+
},
+
"original": {
+
"owner": "juspay",
+
"repo": "rust-flake",
+
"type": "github"
+
}
+
},
+
"rust-overlay": {
+
"inputs": {
+
"nixpkgs": [
+
"rust-flake",
+
"nixpkgs"
+
]
+
},
+
"locked": {
+
"lastModified": 1736700680,
+
"narHash": "sha256-9gmWIb8xsycWHEYpd2SiVIAZnUULX6Y+IMMZBcDUCQU=",
+
"owner": "oxalica",
+
"repo": "rust-overlay",
+
"rev": "5d1865c0da63b4c949f383d982b6b43519946e8f",
+
"type": "github"
+
},
+
"original": {
+
"owner": "oxalica",
+
"repo": "rust-overlay",
+
"type": "github"
+
}
+
},
+
"systems": {
+
"locked": {
+
"lastModified": 1681028828,
+
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+
"owner": "nix-systems",
+
"repo": "default",
+
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+
"type": "github"
+
},
+
"original": {
+
"owner": "nix-systems",
+
"repo": "default",
+
"type": "github"
+
}
+
}
+
},
+
"root": "root",
+
"version": 7
+
}
+26
flake.nix
···
+
{
+
inputs = {
+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
+
flake-parts.url = "github:hercules-ci/flake-parts";
+
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
+
systems.url = "github:nix-systems/default";
+
rust-flake.url = "github:juspay/rust-flake";
+
rust-flake.inputs.nixpkgs.follows = "nixpkgs";
+
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
+
cargo-doc-live.url = "github:srid/cargo-doc-live";
+
+
git-hooks.url = "github:cachix/git-hooks.nix";
+
git-hooks.flake = false;
+
};
+
+
outputs = inputs:
+
inputs.flake-parts.lib.mkFlake {inherit inputs;} {
+
systems = import inputs.systems;
+
+
# See ./nix/modules/*.nix for the modules that are imported here.
+
imports = with builtins;
+
map
+
(fn: ./nix/modules/${fn})
+
(attrNames (readDir ./nix/modules));
+
};
+
}
+14
justfile
···
+
default:
+
@just --list
+
+
# Run pre-commit hooks on all files, including autoformatting
+
pre-commit-all:
+
pre-commit run --all-files
+
+
# Run 'cargo run' on the project
+
run *ARGS:
+
cargo run {{ARGS}}
+
+
# Run 'bacon' to run the project (auto-recompiles)
+
watch *ARGS:
+
bacon --job run -- -- {{ ARGS }}
+23
nix/modules/devshell.nix
···
+
{inputs, ...}: {
+
perSystem = {
+
config,
+
self',
+
pkgs,
+
lib,
+
...
+
}: {
+
devShells.default = pkgs.mkShell {
+
name = "jacquard-shell";
+
inputsFrom = [
+
self'.devShells.rust
+
config.pre-commit.devShell # See ./nix/modules/pre-commit.nix
+
];
+
packages = with pkgs; [
+
just
+
nixd # Nix language server
+
bacon
+
rust-analyzer
+
];
+
};
+
};
+
}
+14
nix/modules/pre-commit.nix
···
+
{ inputs, ... }:
+
{
+
imports = [
+
(inputs.git-hooks + /flake-module.nix)
+
];
+
perSystem = { config, self', pkgs, lib, ... }: {
+
pre-commit.settings = {
+
hooks = {
+
nixpkgs-fmt.enable = true;
+
rustfmt.enable = true;
+
};
+
};
+
};
+
}
+53
nix/modules/rust.nix
···
+
{inputs, ...}: {
+
imports = [
+
inputs.rust-flake.flakeModules.default
+
inputs.rust-flake.flakeModules.nixpkgs
+
# inputs.process-compose-flake.flakeModule
+
# inputs.cargo-doc-live.flakeModule
+
];
+
perSystem = {
+
config,
+
self',
+
pkgs,
+
lib,
+
...
+
}: let
+
inherit (pkgs.stdenv) isDarwin;
+
inherit (pkgs.darwin) apple_sdk;
+
+
# Common configuration for all crates
+
globalCrateConfig = {
+
crane.clippy.enable = false;
+
};
+
+
# Common build inputs for all crates
+
commonBuildInputs = lib.optionals isDarwin (
+
with apple_sdk.frameworks; [
+
IOKit
+
Security
+
SystemConfiguration
+
]
+
);
+
in {
+
rust-project = {
+
# Source filtering to avoid unnecessary rebuilds
+
src = lib.cleanSourceWith {
+
src = inputs.self;
+
filter = config.rust-project.crane-lib.filterCargoSources;
+
};
+
crates = {
+
"jacquard" = {
+
imports = [globalCrateConfig];
+
autoWire = ["crate" "clippy"];
+
path = ./../../crates/jacquard;
+
crane = {
+
args = {
+
buildInputs = commonBuildInputs;
+
};
+
};
+
};
+
};
+
};
+
packages.default = self'.packages.jacquard;
+
};
+
}
+71
nix/modules/template.nix
···
+
{ inputs, ... }:
+
+
{
+
flake = rec {
+
templates.default = {
+
description = "A batteries-included Rust project template for Nix";
+
path = builtins.path { path = inputs.self; };
+
};
+
+
# https://omnix.page/om/init.html#spec
+
om.templates.jacquard = {
+
template = templates.default;
+
params = [
+
{
+
name = "package-name";
+
description = "Name of the Rust package";
+
placeholder = "jacquard";
+
}
+
{
+
name = "author";
+
description = "Author name";
+
placeholder = "Orual";
+
}
+
{
+
name = "author-email";
+
description = "Author email";
+
placeholder = "orual@nonbinary.computer";
+
}
+
{
+
name = "vscode";
+
description = "Include the VSCode settings folder (./.vscode)";
+
paths = [ ".vscode" ];
+
value = true;
+
}
+
{
+
name = "github-ci";
+
description = "Include GitHub Actions workflow configuration";
+
paths = [ ".github" ];
+
value = true;
+
}
+
{
+
name = "nix-template";
+
description = "Keep the flake template in the project";
+
paths = [ "**/template.nix" ];
+
value = false;
+
}
+
];
+
tests = {
+
default = {
+
params = {
+
package-name = "qux";
+
author = "John";
+
author-email = "john@example.com";
+
};
+
asserts = {
+
source = {
+
"Cargo.toml" = true;
+
"flake.nix" = true;
+
".github/workflows/ci.yml" = true;
+
".vscode" = true;
+
"nix/modules/template.nix" = false;
+
};
+
packages.default = {
+
"bin/qux" = true;
+
};
+
};
+
};
+
};
+
};
+
};
+
}
+2
rust-toolchain.toml
···
+
[toolchain]
+
channel = "stable"