From f2c51a87134460e7f2641f38f8d54c0d05500f2c Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 9 Apr 2025 23:20:42 +0100 Subject: [PATCH] build: nixify --- .cspell.yml | 39 +++++++++++ .envrc | 1 + .gitignore | 3 + .taplo.toml | 19 ++++++ .vscode/settings.json | 38 ----------- Cargo.lock | 95 ++++++++++++++++----------- Cargo.toml | 4 +- auth/cookie-auth/Cargo.toml | 2 +- auth/redis-session/Cargo.toml | 2 +- databases/diesel-async/Cargo.toml | 16 ++--- databases/diesel-async/README.md | 3 + databases/diesel-async/src/actions.rs | 4 +- databases/diesel-async/src/main.rs | 3 +- databases/diesel-async/src/models.rs | 3 +- flake.lock | 61 +++++++++++++++++ flake.nix | 28 ++++++++ graphql/async-graphql/Cargo.toml | 2 +- justfile | 9 ++- templating/minijinja/Cargo.toml | 2 +- templating/yarte/Cargo.toml | 2 +- websockets/chat-tcp/Cargo.toml | 2 +- 21 files changed, 237 insertions(+), 101 deletions(-) create mode 100644 .cspell.yml create mode 100644 .envrc create mode 100644 .taplo.toml delete mode 100644 .vscode/settings.json create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.cspell.yml b/.cspell.yml new file mode 100644 index 00000000..f92f8ff8 --- /dev/null +++ b/.cspell.yml @@ -0,0 +1,39 @@ +version: "0.2" +words: + - actix + - addrs + - apalis + - askama + - autoclean + - autoreload + - binstall + - casbin + - chrono + - clippy + - deadpool + - dotenv + - dotenvy + - graphiql + - mainmatter + - minijinja + - nixpkgs + - nocapture + - oneshot + - opentelemetry + - pemfile + - pkgs + - prost + - protobuf + - ractor + - reqwest + - rustls + - rustup + - serde + - sparklepost + - sparkpost + - sqlx + - taplo + - tera + - tmpl + - webpki + - websockets diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..3550a30f --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 2ffc83b4..aaecaf5e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,9 @@ # intellij files **/.idea/** +# direnv +/.direnv/ + .history/ # For multipart example diff --git a/.taplo.toml b/.taplo.toml new file mode 100644 index 00000000..e82aef42 --- /dev/null +++ b/.taplo.toml @@ -0,0 +1,19 @@ +exclude = ["target/*"] +include = ["**/*.toml"] + +[formatting] +column_width = 100 + +[[rule]] +include = ["**/Cargo.toml"] +keys = ["dependencies", "*-dependencies"] + +[rule.formatting] +reorder_keys = true + +[[rule]] +include = ["**/Cargo.toml"] +keys = ["dependencies.*", "*-dependencies.*"] + +[rule.formatting] +reorder_keys = false diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 5e6212bc..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "cSpell.words": [ - "actix", - "addrs", - "apalis", - "askama", - "autoclean", - "autoreload", - "binstall", - "casbin", - "chrono", - "clippy", - "deadpool", - "dotenv", - "dotenvy", - "graphiql", - "mainmatter", - "minijinja", - "nocapture", - "oneshot", - "opentelemetry", - "pemfile", - "prost", - "protobuf", - "ractor", - "reqwest", - "rustls", - "rustup", - "serde", - "sparklepost", - "sparkpost", - "sqlx", - "tera", - "tmpl", - "webpki", - "websockets" - ] -} diff --git a/Cargo.lock b/Cargo.lock index 98485b84..9a7ca885 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,7 +329,7 @@ dependencies = [ "actix-utils", "futures-core", "futures-util", - "mio", + "mio 1.0.3", "socket2", "tokio", "tracing", @@ -2057,7 +2057,7 @@ dependencies = [ "env_logger", "eyre", "log", - "notify", + "notify 6.1.1", "rustls 0.23.25", "tokio", ] @@ -2647,7 +2647,7 @@ dependencies = [ [[package]] name = "db-diesel-async" -version = "1.0.0" +version = "0.0.0" dependencies = [ "actix-web", "diesel", @@ -2689,7 +2689,7 @@ version = "0.0.0" dependencies = [ "actix-web", "env_logger", - "redis 0.28.2", + "redis 0.27.6", "serde", "tracing", ] @@ -3129,7 +3129,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -4416,6 +4416,17 @@ dependencies = [ "serde", ] +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + [[package]] name = "inotify" version = "0.11.0" @@ -4830,7 +4841,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -5202,7 +5213,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bfa27f77378f5239b971abf45c16b56f6f207c0186f5b62ee2aee1be19dd6ce" dependencies = [ "minijinja", - "notify", + "notify 8.0.0", ] [[package]] @@ -5229,6 +5240,18 @@ dependencies = [ "adler2", ] +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.48.0", +] + [[package]] name = "mio" version = "1.0.3" @@ -5520,6 +5543,25 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.9.0", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify 0.9.6", + "kqueue", + "libc", + "log", + "mio 0.8.11", + "walkdir", + "windows-sys 0.48.0", +] + [[package]] name = "notify" version = "8.0.0" @@ -5529,11 +5571,11 @@ dependencies = [ "bitflags 2.9.0", "filetime", "fsevent-sys", - "inotify", + "inotify 0.11.0", "kqueue", "libc", "log", - "mio", + "mio 1.0.3", "notify-types", "walkdir", "windows-sys 0.59.0", @@ -6407,7 +6449,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -6579,29 +6621,6 @@ dependencies = [ "pin-project-lite", "ryu", "sha1_smol", - "tokio", - "tokio-util", - "url", -] - -[[package]] -name = "redis" -version = "0.28.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e37ec3fd44bea2ec947ba6cc7634d7999a6590aca7c35827c250bc0de502bda6" -dependencies = [ - "arc-swap", - "backon", - "bytes", - "combine", - "futures-channel", - "futures-util", - "itoa", - "num-bigint", - "percent-encoding", - "pin-project-lite", - "ryu", - "sha1_smol", "socket2", "tokio", "tokio-util", @@ -6948,7 +6967,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -6961,7 +6980,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.9.3", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -8160,7 +8179,7 @@ dependencies = [ "getrandom 0.3.2", "once_cell", "rustix 1.0.3", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -8497,7 +8516,7 @@ dependencies = [ "backtrace", "bytes", "libc", - "mio", + "mio 1.0.3", "parking_lot", "pin-project-lite", "signal-hook-registry", @@ -9669,7 +9688,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a234b0e3..847faa4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,9 +69,7 @@ members = [ "websockets/echo-actorless", "websockets/echo", ] -exclude = [ - "databases/sqlite", -] +exclude = ["databases/sqlite"] [workspace.package] publish = false diff --git a/auth/cookie-auth/Cargo.toml b/auth/cookie-auth/Cargo.toml index dd704da8..10e3e0b6 100644 --- a/auth/cookie-auth/Cargo.toml +++ b/auth/cookie-auth/Cargo.toml @@ -4,9 +4,9 @@ edition.workspace = true rust-version.workspace = true [dependencies] -actix-web.workspace = true actix-identity.workspace = true actix-session = { workspace = true, features = ["cookie-session"] } +actix-web.workspace = true env_logger.workspace = true log.workspace = true diff --git a/auth/redis-session/Cargo.toml b/auth/redis-session/Cargo.toml index 65d2ecc5..218ce58f 100644 --- a/auth/redis-session/Cargo.toml +++ b/auth/redis-session/Cargo.toml @@ -4,8 +4,8 @@ edition.workspace = true rust-version.workspace = true [dependencies] -actix-web.workspace = true actix-session = { workspace = true, features = ["redis-session"] } +actix-web.workspace = true env_logger.workspace = true log.workspace = true diff --git a/databases/diesel-async/Cargo.toml b/databases/diesel-async/Cargo.toml index fbf35f2f..67dc5211 100644 --- a/databases/diesel-async/Cargo.toml +++ b/databases/diesel-async/Cargo.toml @@ -1,17 +1,17 @@ [package] name = "db-diesel-async" -version = "1.0.0" -edition = "2021" +edition.workspace = true +rust-version.workspace = true [features] postgres_tests = [] [dependencies] -actix-web.workspace = true +actix-web = { workspace = true } diesel = { version = "2", default-features = false, features = ["uuid"] } diesel-async = { version = "0.5", features = ["postgres", "bb8", "async-connection-wrapper"] } -serde.workspace = true -uuid.workspace = true -dotenvy.workspace = true -env_logger.workspace = true -log.workspace = true +dotenvy = { workspace = true } +env_logger = { workspace = true } +log = { workspace = true } +serde = { workspace = true } +uuid = { workspace = true } diff --git a/databases/diesel-async/README.md b/databases/diesel-async/README.md index 891e55b5..01116f4d 100644 --- a/databases/diesel-async/README.md +++ b/databases/diesel-async/README.md @@ -10,7 +10,9 @@ Basic integration of [Diesel-async](https://github.com/weiznich/diesel_async) us # on any OS docker run -d --restart unless-stopped --name postgresql -e POSTGRES_USER=test-user -e POSTGRES_PASSWORD=password -p 5432:5432 -v postgres_data:/var/lib/postgresql/data postgres:alpine ``` + make sure it has successfully started up and is running + ```sh # on any OS docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}" @@ -28,6 +30,7 @@ diesel migration run ``` The database will now be created in your PostgreSQL instance. + ```sh docker exec -i postgresql psql -U test-user -c "\l" ``` diff --git a/databases/diesel-async/src/actions.rs b/databases/diesel-async/src/actions.rs index 542f5662..227aa038 100644 --- a/databases/diesel-async/src/actions.rs +++ b/databases/diesel-async/src/actions.rs @@ -1,11 +1,9 @@ use diesel::prelude::*; +use diesel_async::{AsyncPgConnection, RunQueryDsl}; use uuid::{NoContext, Timestamp, Uuid}; use crate::models; -use diesel_async::AsyncPgConnection; -use diesel_async::RunQueryDsl; - type DbError = Box; // /// Run query using Diesel to find item by uid and return it. diff --git a/databases/diesel-async/src/main.rs b/databases/diesel-async/src/main.rs index 5d315c01..82630220 100644 --- a/databases/diesel-async/src/main.rs +++ b/databases/diesel-async/src/main.rs @@ -1,13 +1,14 @@ #[macro_use] extern crate diesel; +use std::{env, io}; + use actix_web::{error, get, middleware, post, web, App, HttpResponse, HttpServer, Responder}; use diesel_async::{ pooled_connection::{bb8::Pool, AsyncDieselConnectionManager}, AsyncPgConnection, }; use dotenvy::dotenv; -use std::{env, io}; use uuid::Uuid; mod actions; diff --git a/databases/diesel-async/src/models.rs b/databases/diesel-async/src/models.rs index 610839ba..a2086897 100644 --- a/databases/diesel-async/src/models.rs +++ b/databases/diesel-async/src/models.rs @@ -1,7 +1,8 @@ -use super::schema::items; use serde::{Deserialize, Serialize}; use uuid::Uuid; +use super::schema::items; + /// Item details. #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable, Insertable)] #[diesel(table_name = items)] diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..98e79e59 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1743550720, + "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c621e8422220273271f52058f618c94e405bb0f5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1744168086, + "narHash": "sha256-S9M4HddBCxbbX1CKSyDYgZ8NCVyHcbKnBfoUXeRu2jQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "60e405b241edb6f0573f3d9f944617fe33ac4a73", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1743296961, + "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..70a2e694 --- /dev/null +++ b/flake.nix @@ -0,0 +1,28 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + perSystem = { pkgs, config, inputs', system, lib, ... }: { + formatter = pkgs.nixpkgs-fmt; + + devShells.default = pkgs.mkShell { + packages = [ + config.formatter + pkgs.nodePackages.prettier + pkgs.taplo + pkgs.just + ] ++ lib.optional pkgs.stdenv.isDarwin [ + pkgs.pkgsBuildHost.libiconv + pkgs.pkgsBuildHost.darwin.apple_sdk.frameworks.Security + pkgs.pkgsBuildHost.darwin.apple_sdk.frameworks.CoreFoundation + pkgs.pkgsBuildHost.darwin.apple_sdk.frameworks.SystemConfiguration + ]; + }; + }; + }; +} diff --git a/graphql/async-graphql/Cargo.toml b/graphql/async-graphql/Cargo.toml index 70e9e91f..48032d05 100644 --- a/graphql/async-graphql/Cargo.toml +++ b/graphql/async-graphql/Cargo.toml @@ -4,8 +4,8 @@ edition.workspace = true rust-version.workspace = true [dependencies] -actix-web.workspace = true actix-cors.workspace = true +actix-web.workspace = true async-graphql = "6" async-graphql-actix-web = "6" env_logger.workspace = true diff --git a/justfile b/justfile index 9148d8d4..43611686 100644 --- a/justfile +++ b/justfile @@ -4,13 +4,16 @@ _list: # Format project. [group("lint")] fmt: + fd --type=file --hidden --extension=yml --extension=md --extension=js --exec-batch prettier --write + fd --hidden --extension=toml --exec-batch taplo format cargo +nightly fmt - fd --type=file --hidden --extension=yml --extension=md --extension=js --exec-batch npx -y prettier --write # Check project. [group("lint")] -check: clippy - fd --type=file --hidden --extension=yml --extension=md --extension=js --exec-batch npx -y prettier --check +check: && clippy + fd --type=file --hidden --extension=yml --extension=md --extension=js --exec-batch prettier --check + fd --hidden --extension=toml --exec-batch taplo format --check + fd --hidden --extension=toml --exec-batch taplo lint # Run Clippy over workspace. [group("lint")] diff --git a/templating/minijinja/Cargo.toml b/templating/minijinja/Cargo.toml index ee237c09..4ee65b0d 100644 --- a/templating/minijinja/Cargo.toml +++ b/templating/minijinja/Cargo.toml @@ -4,8 +4,8 @@ edition.workspace = true rust-version.workspace = true [dependencies] -actix-web.workspace = true actix-utils.workspace = true +actix-web.workspace = true env_logger.workspace = true log.workspace = true minijinja = { version = "2", features = ["loader"] } diff --git a/templating/yarte/Cargo.toml b/templating/yarte/Cargo.toml index 012fdef8..cbceea29 100644 --- a/templating/yarte/Cargo.toml +++ b/templating/yarte/Cargo.toml @@ -6,7 +6,7 @@ publish = false [package.metadata.cargo-machete] ignored = [ - "yarte_helpers" # only used as build dependency + "yarte_helpers", # only used as build dependency ] [dependencies] diff --git a/websockets/chat-tcp/Cargo.toml b/websockets/chat-tcp/Cargo.toml index 31a9ac45..7c306faa 100644 --- a/websockets/chat-tcp/Cargo.toml +++ b/websockets/chat-tcp/Cargo.toml @@ -26,5 +26,5 @@ rand.workspace = true serde.workspace = true serde_json.workspace = true tokio = { workspace = true, features = ["full"] } -tokio-util.workspace = true tokio-stream = "0.1.8" +tokio-util.workspace = true