A better Rust ATProto crate

init

Orual 4ae6df30

+8
.envrc
··· 1 + if ! has nix_direnv_version || ! nix_direnv_version 3.1.0; then 2 + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.1.0/direnvrc" "sha256-yMJ2OVMzrFaDPn7q8nCBZFRYpL/f0RcHzhmw/i6btJM=" 3 + fi 4 + 5 + watch_file \ 6 + rust-toolchain.toml \ 7 + nix/modules/*.nix 8 + use flake
+1
.gitattributes
··· 1 + flake.lock linguist-generated=true
+19
.github/workflows/ci-nix.yml
··· 1 + name: "CI Nix" 2 + on: 3 + # Run only when pushing to master branch, and making PRs 4 + push: 5 + branches: 6 + - master 7 + pull_request: 8 + jobs: 9 + build: 10 + runs-on: ${{ matrix.os }} 11 + strategy: 12 + matrix: 13 + os: [ubuntu-latest, macos-14] 14 + steps: 15 + - uses: actions/checkout@v4 16 + - uses: nixbuild/nix-quick-install-action@v33 17 + - name: Install omnix 18 + run: nix --accept-flake-config profile install "github:juspay/omnix" 19 + - run: om ci
+24
.github/workflows/ci.yml
··· 1 + on: [push] 2 + 3 + name: CI 4 + 5 + jobs: 6 + check: 7 + name: Rust project 8 + runs-on: ubuntu-latest 9 + steps: 10 + - uses: actions/checkout@v2 11 + - name: Install latest nightly 12 + uses: actions-rs/toolchain@v1 13 + with: 14 + toolchain: nightly 15 + override: true 16 + components: rustfmt, clippy 17 + 18 + # `cargo check` command here will use installed `nightly` 19 + # as it is set as an "override" for current directory 20 + 21 + - name: Run cargo check 22 + uses: actions-rs/cargo@v1 23 + with: 24 + command: check
+6
.gitignore
··· 1 + /target 2 + /result 3 + /result-lib 4 + .direnv 5 + 6 + /.pre-commit-config.yaml
+9
.vscode/extensions.json
··· 1 + { 2 + "recommendations": [ 3 + "rust-lang.rust-analyzer", 4 + "jnoortheen.nix-ide", 5 + "mkhl.direnv", 6 + "tamasfe.even-better-toml", 7 + "fill-labs.dependi" 8 + ] 9 + }
+8
.vscode/settings.json
··· 1 + { 2 + "editor.formatOnSave": true, 3 + "rust-analyzer.files.excludeDirs": [ 4 + ".direnv" 5 + ], 6 + // https://twitter.com/sridca/status/1674947342607216641 7 + // "editor.inlayHints.enabled": "offUnlessPressed", 8 + }
+251
Cargo.lock
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "anstream" 7 + version = "0.6.20" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" 10 + dependencies = [ 11 + "anstyle", 12 + "anstyle-parse", 13 + "anstyle-query", 14 + "anstyle-wincon", 15 + "colorchoice", 16 + "is_terminal_polyfill", 17 + "utf8parse", 18 + ] 19 + 20 + [[package]] 21 + name = "anstyle" 22 + version = "1.0.11" 23 + source = "registry+https://github.com/rust-lang/crates.io-index" 24 + checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" 25 + 26 + [[package]] 27 + name = "anstyle-parse" 28 + version = "0.2.7" 29 + source = "registry+https://github.com/rust-lang/crates.io-index" 30 + checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" 31 + dependencies = [ 32 + "utf8parse", 33 + ] 34 + 35 + [[package]] 36 + name = "anstyle-query" 37 + version = "1.1.4" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" 40 + dependencies = [ 41 + "windows-sys", 42 + ] 43 + 44 + [[package]] 45 + name = "anstyle-wincon" 46 + version = "3.0.10" 47 + source = "registry+https://github.com/rust-lang/crates.io-index" 48 + checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" 49 + dependencies = [ 50 + "anstyle", 51 + "once_cell_polyfill", 52 + "windows-sys", 53 + ] 54 + 55 + [[package]] 56 + name = "clap" 57 + version = "4.5.48" 58 + source = "registry+https://github.com/rust-lang/crates.io-index" 59 + checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae" 60 + dependencies = [ 61 + "clap_builder", 62 + "clap_derive", 63 + ] 64 + 65 + [[package]] 66 + name = "clap_builder" 67 + version = "4.5.48" 68 + source = "registry+https://github.com/rust-lang/crates.io-index" 69 + checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9" 70 + dependencies = [ 71 + "anstream", 72 + "anstyle", 73 + "clap_lex", 74 + "strsim", 75 + ] 76 + 77 + [[package]] 78 + name = "clap_derive" 79 + version = "4.5.47" 80 + source = "registry+https://github.com/rust-lang/crates.io-index" 81 + checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" 82 + dependencies = [ 83 + "heck", 84 + "proc-macro2", 85 + "quote", 86 + "syn", 87 + ] 88 + 89 + [[package]] 90 + name = "clap_lex" 91 + version = "0.7.5" 92 + source = "registry+https://github.com/rust-lang/crates.io-index" 93 + checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" 94 + 95 + [[package]] 96 + name = "colorchoice" 97 + version = "1.0.4" 98 + source = "registry+https://github.com/rust-lang/crates.io-index" 99 + checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" 100 + 101 + [[package]] 102 + name = "heck" 103 + version = "0.5.0" 104 + source = "registry+https://github.com/rust-lang/crates.io-index" 105 + checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 106 + 107 + [[package]] 108 + name = "is_terminal_polyfill" 109 + version = "1.70.1" 110 + source = "registry+https://github.com/rust-lang/crates.io-index" 111 + checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" 112 + 113 + [[package]] 114 + name = "jacquard" 115 + version = "0.1.0" 116 + dependencies = [ 117 + "clap", 118 + ] 119 + 120 + [[package]] 121 + name = "once_cell_polyfill" 122 + version = "1.70.1" 123 + source = "registry+https://github.com/rust-lang/crates.io-index" 124 + checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" 125 + 126 + [[package]] 127 + name = "proc-macro2" 128 + version = "1.0.101" 129 + source = "registry+https://github.com/rust-lang/crates.io-index" 130 + checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" 131 + dependencies = [ 132 + "unicode-ident", 133 + ] 134 + 135 + [[package]] 136 + name = "quote" 137 + version = "1.0.40" 138 + source = "registry+https://github.com/rust-lang/crates.io-index" 139 + checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" 140 + dependencies = [ 141 + "proc-macro2", 142 + ] 143 + 144 + [[package]] 145 + name = "strsim" 146 + version = "0.11.1" 147 + source = "registry+https://github.com/rust-lang/crates.io-index" 148 + checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 149 + 150 + [[package]] 151 + name = "syn" 152 + version = "2.0.106" 153 + source = "registry+https://github.com/rust-lang/crates.io-index" 154 + checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" 155 + dependencies = [ 156 + "proc-macro2", 157 + "quote", 158 + "unicode-ident", 159 + ] 160 + 161 + [[package]] 162 + name = "unicode-ident" 163 + version = "1.0.19" 164 + source = "registry+https://github.com/rust-lang/crates.io-index" 165 + checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" 166 + 167 + [[package]] 168 + name = "utf8parse" 169 + version = "0.2.2" 170 + source = "registry+https://github.com/rust-lang/crates.io-index" 171 + checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 172 + 173 + [[package]] 174 + name = "windows-link" 175 + version = "0.2.0" 176 + source = "registry+https://github.com/rust-lang/crates.io-index" 177 + checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" 178 + 179 + [[package]] 180 + name = "windows-sys" 181 + version = "0.60.2" 182 + source = "registry+https://github.com/rust-lang/crates.io-index" 183 + checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" 184 + dependencies = [ 185 + "windows-targets", 186 + ] 187 + 188 + [[package]] 189 + name = "windows-targets" 190 + version = "0.53.4" 191 + source = "registry+https://github.com/rust-lang/crates.io-index" 192 + checksum = "2d42b7b7f66d2a06854650af09cfdf8713e427a439c97ad65a6375318033ac4b" 193 + dependencies = [ 194 + "windows-link", 195 + "windows_aarch64_gnullvm", 196 + "windows_aarch64_msvc", 197 + "windows_i686_gnu", 198 + "windows_i686_gnullvm", 199 + "windows_i686_msvc", 200 + "windows_x86_64_gnu", 201 + "windows_x86_64_gnullvm", 202 + "windows_x86_64_msvc", 203 + ] 204 + 205 + [[package]] 206 + name = "windows_aarch64_gnullvm" 207 + version = "0.53.0" 208 + source = "registry+https://github.com/rust-lang/crates.io-index" 209 + checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" 210 + 211 + [[package]] 212 + name = "windows_aarch64_msvc" 213 + version = "0.53.0" 214 + source = "registry+https://github.com/rust-lang/crates.io-index" 215 + checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" 216 + 217 + [[package]] 218 + name = "windows_i686_gnu" 219 + version = "0.53.0" 220 + source = "registry+https://github.com/rust-lang/crates.io-index" 221 + checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" 222 + 223 + [[package]] 224 + name = "windows_i686_gnullvm" 225 + version = "0.53.0" 226 + source = "registry+https://github.com/rust-lang/crates.io-index" 227 + checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" 228 + 229 + [[package]] 230 + name = "windows_i686_msvc" 231 + version = "0.53.0" 232 + source = "registry+https://github.com/rust-lang/crates.io-index" 233 + checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" 234 + 235 + [[package]] 236 + name = "windows_x86_64_gnu" 237 + version = "0.53.0" 238 + source = "registry+https://github.com/rust-lang/crates.io-index" 239 + checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" 240 + 241 + [[package]] 242 + name = "windows_x86_64_gnullvm" 243 + version = "0.53.0" 244 + source = "registry+https://github.com/rust-lang/crates.io-index" 245 + checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" 246 + 247 + [[package]] 248 + name = "windows_x86_64_msvc" 249 + version = "0.53.0" 250 + source = "registry+https://github.com/rust-lang/crates.io-index" 251 + checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
+15
Cargo.toml
··· 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
··· 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.
+50
README.md
··· 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
··· 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
··· 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 + }
+172
flake.lock
··· 1 + { 2 + "nodes": { 3 + "cargo-doc-live": { 4 + "locked": { 5 + "lastModified": 1724704668, 6 + "narHash": "sha256-kJFYXlWUodg5WhJ0NuvrP0mCvOT/2AOIo8oGeYLXocs=", 7 + "owner": "srid", 8 + "repo": "cargo-doc-live", 9 + "rev": "b09d5d258d2498829e03014931fc19aed499b86f", 10 + "type": "github" 11 + }, 12 + "original": { 13 + "owner": "srid", 14 + "repo": "cargo-doc-live", 15 + "type": "github" 16 + } 17 + }, 18 + "crane": { 19 + "locked": { 20 + "lastModified": 1736566337, 21 + "narHash": "sha256-SC0eDcZPqISVt6R0UfGPyQLrI0+BppjjtQ3wcSlk0oI=", 22 + "owner": "ipetkov", 23 + "repo": "crane", 24 + "rev": "9172acc1ee6c7e1cbafc3044ff850c568c75a5a3", 25 + "type": "github" 26 + }, 27 + "original": { 28 + "owner": "ipetkov", 29 + "repo": "crane", 30 + "type": "github" 31 + } 32 + }, 33 + "flake-parts": { 34 + "inputs": { 35 + "nixpkgs-lib": [ 36 + "nixpkgs" 37 + ] 38 + }, 39 + "locked": { 40 + "lastModified": 1725234343, 41 + "narHash": "sha256-+ebgonl3NbiKD2UD0x4BszCZQ6sTfL4xioaM49o5B3Y=", 42 + "owner": "hercules-ci", 43 + "repo": "flake-parts", 44 + "rev": "567b938d64d4b4112ee253b9274472dc3a346eb6", 45 + "type": "github" 46 + }, 47 + "original": { 48 + "owner": "hercules-ci", 49 + "repo": "flake-parts", 50 + "type": "github" 51 + } 52 + }, 53 + "git-hooks": { 54 + "flake": false, 55 + "locked": { 56 + "lastModified": 1734425854, 57 + "narHash": "sha256-nzE5UbJ41aPEKf8R2ZFYtLkqPmF7EIUbNEdHMBLg0Ig=", 58 + "owner": "cachix", 59 + "repo": "git-hooks.nix", 60 + "rev": "0ddd26d0925f618c3a5d85a4fa5eb1e23a09491d", 61 + "type": "github" 62 + }, 63 + "original": { 64 + "owner": "cachix", 65 + "repo": "git-hooks.nix", 66 + "type": "github" 67 + } 68 + }, 69 + "nixpkgs": { 70 + "locked": { 71 + "lastModified": 1736693123, 72 + "narHash": "sha256-9lIfXCaBPwUA7FnfDnoH4gxxdOvXG78k6UlUw0+ZDxc=", 73 + "owner": "nixos", 74 + "repo": "nixpkgs", 75 + "rev": "2fdec2c2e68b7b7845d1ea4e0894c63143e3261b", 76 + "type": "github" 77 + }, 78 + "original": { 79 + "owner": "nixos", 80 + "ref": "nixpkgs-unstable", 81 + "repo": "nixpkgs", 82 + "type": "github" 83 + } 84 + }, 85 + "process-compose-flake": { 86 + "locked": { 87 + "lastModified": 1724606023, 88 + "narHash": "sha256-rdGeNa/lCS8E1lXzPqgl+vZUUvnbEZT11Bqkx5jfYug=", 89 + "owner": "Platonic-Systems", 90 + "repo": "process-compose-flake", 91 + "rev": "f6ce9481df9aec739e4e06b67492401a5bb4f0b1", 92 + "type": "github" 93 + }, 94 + "original": { 95 + "owner": "Platonic-Systems", 96 + "repo": "process-compose-flake", 97 + "type": "github" 98 + } 99 + }, 100 + "root": { 101 + "inputs": { 102 + "cargo-doc-live": "cargo-doc-live", 103 + "flake-parts": "flake-parts", 104 + "git-hooks": "git-hooks", 105 + "nixpkgs": "nixpkgs", 106 + "process-compose-flake": "process-compose-flake", 107 + "rust-flake": "rust-flake", 108 + "systems": "systems" 109 + } 110 + }, 111 + "rust-flake": { 112 + "inputs": { 113 + "crane": "crane", 114 + "nixpkgs": [ 115 + "nixpkgs" 116 + ], 117 + "rust-overlay": "rust-overlay" 118 + }, 119 + "locked": { 120 + "lastModified": 1736806612, 121 + "narHash": "sha256-WioA+Vk7suDK+Ek77rDlbuxV6WqwFt30JsKHrmDCSiU=", 122 + "owner": "juspay", 123 + "repo": "rust-flake", 124 + "rev": "b5f39885e2fcf137bfaf75decc077f9cca2bd984", 125 + "type": "github" 126 + }, 127 + "original": { 128 + "owner": "juspay", 129 + "repo": "rust-flake", 130 + "type": "github" 131 + } 132 + }, 133 + "rust-overlay": { 134 + "inputs": { 135 + "nixpkgs": [ 136 + "rust-flake", 137 + "nixpkgs" 138 + ] 139 + }, 140 + "locked": { 141 + "lastModified": 1736700680, 142 + "narHash": "sha256-9gmWIb8xsycWHEYpd2SiVIAZnUULX6Y+IMMZBcDUCQU=", 143 + "owner": "oxalica", 144 + "repo": "rust-overlay", 145 + "rev": "5d1865c0da63b4c949f383d982b6b43519946e8f", 146 + "type": "github" 147 + }, 148 + "original": { 149 + "owner": "oxalica", 150 + "repo": "rust-overlay", 151 + "type": "github" 152 + } 153 + }, 154 + "systems": { 155 + "locked": { 156 + "lastModified": 1681028828, 157 + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 158 + "owner": "nix-systems", 159 + "repo": "default", 160 + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 161 + "type": "github" 162 + }, 163 + "original": { 164 + "owner": "nix-systems", 165 + "repo": "default", 166 + "type": "github" 167 + } 168 + } 169 + }, 170 + "root": "root", 171 + "version": 7 172 + }
+26
flake.nix
··· 1 + { 2 + inputs = { 3 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 4 + flake-parts.url = "github:hercules-ci/flake-parts"; 5 + flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; 6 + systems.url = "github:nix-systems/default"; 7 + rust-flake.url = "github:juspay/rust-flake"; 8 + rust-flake.inputs.nixpkgs.follows = "nixpkgs"; 9 + process-compose-flake.url = "github:Platonic-Systems/process-compose-flake"; 10 + cargo-doc-live.url = "github:srid/cargo-doc-live"; 11 + 12 + git-hooks.url = "github:cachix/git-hooks.nix"; 13 + git-hooks.flake = false; 14 + }; 15 + 16 + outputs = inputs: 17 + inputs.flake-parts.lib.mkFlake {inherit inputs;} { 18 + systems = import inputs.systems; 19 + 20 + # See ./nix/modules/*.nix for the modules that are imported here. 21 + imports = with builtins; 22 + map 23 + (fn: ./nix/modules/${fn}) 24 + (attrNames (readDir ./nix/modules)); 25 + }; 26 + }
+14
justfile
··· 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 }}
+23
nix/modules/devshell.nix
··· 1 + {inputs, ...}: { 2 + perSystem = { 3 + config, 4 + self', 5 + pkgs, 6 + lib, 7 + ... 8 + }: { 9 + devShells.default = pkgs.mkShell { 10 + name = "jacquard-shell"; 11 + inputsFrom = [ 12 + self'.devShells.rust 13 + config.pre-commit.devShell # See ./nix/modules/pre-commit.nix 14 + ]; 15 + packages = with pkgs; [ 16 + just 17 + nixd # Nix language server 18 + bacon 19 + rust-analyzer 20 + ]; 21 + }; 22 + }; 23 + }
+14
nix/modules/pre-commit.nix
··· 1 + { inputs, ... }: 2 + { 3 + imports = [ 4 + (inputs.git-hooks + /flake-module.nix) 5 + ]; 6 + perSystem = { config, self', pkgs, lib, ... }: { 7 + pre-commit.settings = { 8 + hooks = { 9 + nixpkgs-fmt.enable = true; 10 + rustfmt.enable = true; 11 + }; 12 + }; 13 + }; 14 + }
+53
nix/modules/rust.nix
··· 1 + {inputs, ...}: { 2 + imports = [ 3 + inputs.rust-flake.flakeModules.default 4 + inputs.rust-flake.flakeModules.nixpkgs 5 + # inputs.process-compose-flake.flakeModule 6 + # inputs.cargo-doc-live.flakeModule 7 + ]; 8 + perSystem = { 9 + config, 10 + self', 11 + pkgs, 12 + lib, 13 + ... 14 + }: let 15 + inherit (pkgs.stdenv) isDarwin; 16 + inherit (pkgs.darwin) apple_sdk; 17 + 18 + # Common configuration for all crates 19 + globalCrateConfig = { 20 + crane.clippy.enable = false; 21 + }; 22 + 23 + # Common build inputs for all crates 24 + commonBuildInputs = lib.optionals isDarwin ( 25 + with apple_sdk.frameworks; [ 26 + IOKit 27 + Security 28 + SystemConfiguration 29 + ] 30 + ); 31 + in { 32 + rust-project = { 33 + # Source filtering to avoid unnecessary rebuilds 34 + src = lib.cleanSourceWith { 35 + src = inputs.self; 36 + filter = config.rust-project.crane-lib.filterCargoSources; 37 + }; 38 + crates = { 39 + "jacquard" = { 40 + imports = [globalCrateConfig]; 41 + autoWire = ["crate" "clippy"]; 42 + path = ./../../crates/jacquard; 43 + crane = { 44 + args = { 45 + buildInputs = commonBuildInputs; 46 + }; 47 + }; 48 + }; 49 + }; 50 + }; 51 + packages.default = self'.packages.jacquard; 52 + }; 53 + }
+71
nix/modules/template.nix
··· 1 + { inputs, ... }: 2 + 3 + { 4 + flake = rec { 5 + templates.default = { 6 + description = "A batteries-included Rust project template for Nix"; 7 + path = builtins.path { path = inputs.self; }; 8 + }; 9 + 10 + # https://omnix.page/om/init.html#spec 11 + om.templates.jacquard = { 12 + template = templates.default; 13 + params = [ 14 + { 15 + name = "package-name"; 16 + description = "Name of the Rust package"; 17 + placeholder = "jacquard"; 18 + } 19 + { 20 + name = "author"; 21 + description = "Author name"; 22 + placeholder = "Orual"; 23 + } 24 + { 25 + name = "author-email"; 26 + description = "Author email"; 27 + placeholder = "orual@nonbinary.computer"; 28 + } 29 + { 30 + name = "vscode"; 31 + description = "Include the VSCode settings folder (./.vscode)"; 32 + paths = [ ".vscode" ]; 33 + value = true; 34 + } 35 + { 36 + name = "github-ci"; 37 + description = "Include GitHub Actions workflow configuration"; 38 + paths = [ ".github" ]; 39 + value = true; 40 + } 41 + { 42 + name = "nix-template"; 43 + description = "Keep the flake template in the project"; 44 + paths = [ "**/template.nix" ]; 45 + value = false; 46 + } 47 + ]; 48 + tests = { 49 + default = { 50 + params = { 51 + package-name = "qux"; 52 + author = "John"; 53 + author-email = "john@example.com"; 54 + }; 55 + asserts = { 56 + source = { 57 + "Cargo.toml" = true; 58 + "flake.nix" = true; 59 + ".github/workflows/ci.yml" = true; 60 + ".vscode" = true; 61 + "nix/modules/template.nix" = false; 62 + }; 63 + packages.default = { 64 + "bin/qux" = true; 65 + }; 66 + }; 67 + }; 68 + }; 69 + }; 70 + }; 71 + }
+2
rust-toolchain.toml
··· 1 + [toolchain] 2 + channel = "stable"