1
0
mirror of https://github.com/actix/examples synced 2025-04-22 08:34:52 +02:00

build: nixify

This commit is contained in:
Rob Ede 2025-04-09 23:20:42 +01:00
parent c5ce3c118e
commit f2c51a8713
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
21 changed files with 237 additions and 101 deletions

39
.cspell.yml Normal file
View File

@ -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

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

3
.gitignore vendored
View File

@ -13,6 +13,9 @@
# intellij files # intellij files
**/.idea/** **/.idea/**
# direnv
/.direnv/
.history/ .history/
# For multipart example # For multipart example

19
.taplo.toml Normal file
View File

@ -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

38
.vscode/settings.json vendored
View File

@ -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"
]
}

95
Cargo.lock generated
View File

@ -329,7 +329,7 @@ dependencies = [
"actix-utils", "actix-utils",
"futures-core", "futures-core",
"futures-util", "futures-util",
"mio", "mio 1.0.3",
"socket2", "socket2",
"tokio", "tokio",
"tracing", "tracing",
@ -2057,7 +2057,7 @@ dependencies = [
"env_logger", "env_logger",
"eyre", "eyre",
"log", "log",
"notify", "notify 6.1.1",
"rustls 0.23.25", "rustls 0.23.25",
"tokio", "tokio",
] ]
@ -2647,7 +2647,7 @@ dependencies = [
[[package]] [[package]]
name = "db-diesel-async" name = "db-diesel-async"
version = "1.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"diesel", "diesel",
@ -2689,7 +2689,7 @@ version = "0.0.0"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"env_logger", "env_logger",
"redis 0.28.2", "redis 0.27.6",
"serde", "serde",
"tracing", "tracing",
] ]
@ -3129,7 +3129,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -4416,6 +4416,17 @@ dependencies = [
"serde", "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]] [[package]]
name = "inotify" name = "inotify"
version = "0.11.0" version = "0.11.0"
@ -4830,7 +4841,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-targets 0.48.5", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -5202,7 +5213,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bfa27f77378f5239b971abf45c16b56f6f207c0186f5b62ee2aee1be19dd6ce" checksum = "2bfa27f77378f5239b971abf45c16b56f6f207c0186f5b62ee2aee1be19dd6ce"
dependencies = [ dependencies = [
"minijinja", "minijinja",
"notify", "notify 8.0.0",
] ]
[[package]] [[package]]
@ -5229,6 +5240,18 @@ dependencies = [
"adler2", "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]] [[package]]
name = "mio" name = "mio"
version = "1.0.3" version = "1.0.3"
@ -5520,6 +5543,25 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" 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]] [[package]]
name = "notify" name = "notify"
version = "8.0.0" version = "8.0.0"
@ -5529,11 +5571,11 @@ dependencies = [
"bitflags 2.9.0", "bitflags 2.9.0",
"filetime", "filetime",
"fsevent-sys", "fsevent-sys",
"inotify", "inotify 0.11.0",
"kqueue", "kqueue",
"libc", "libc",
"log", "log",
"mio", "mio 1.0.3",
"notify-types", "notify-types",
"walkdir", "walkdir",
"windows-sys 0.59.0", "windows-sys 0.59.0",
@ -6407,7 +6449,7 @@ dependencies = [
"once_cell", "once_cell",
"socket2", "socket2",
"tracing", "tracing",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -6579,29 +6621,6 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
"ryu", "ryu",
"sha1_smol", "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", "socket2",
"tokio", "tokio",
"tokio-util", "tokio-util",
@ -6948,7 +6967,7 @@ dependencies = [
"errno", "errno",
"libc", "libc",
"linux-raw-sys 0.4.15", "linux-raw-sys 0.4.15",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -6961,7 +6980,7 @@ dependencies = [
"errno", "errno",
"libc", "libc",
"linux-raw-sys 0.9.3", "linux-raw-sys 0.9.3",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -8160,7 +8179,7 @@ dependencies = [
"getrandom 0.3.2", "getrandom 0.3.2",
"once_cell", "once_cell",
"rustix 1.0.3", "rustix 1.0.3",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -8497,7 +8516,7 @@ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",
"libc", "libc",
"mio", "mio 1.0.3",
"parking_lot", "parking_lot",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry", "signal-hook-registry",
@ -9669,7 +9688,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]

View File

@ -69,9 +69,7 @@ members = [
"websockets/echo-actorless", "websockets/echo-actorless",
"websockets/echo", "websockets/echo",
] ]
exclude = [ exclude = ["databases/sqlite"]
"databases/sqlite",
]
[workspace.package] [workspace.package]
publish = false publish = false

View File

@ -4,9 +4,9 @@ edition.workspace = true
rust-version.workspace = true rust-version.workspace = true
[dependencies] [dependencies]
actix-web.workspace = true
actix-identity.workspace = true actix-identity.workspace = true
actix-session = { workspace = true, features = ["cookie-session"] } actix-session = { workspace = true, features = ["cookie-session"] }
actix-web.workspace = true
env_logger.workspace = true env_logger.workspace = true
log.workspace = true log.workspace = true

View File

@ -4,8 +4,8 @@ edition.workspace = true
rust-version.workspace = true rust-version.workspace = true
[dependencies] [dependencies]
actix-web.workspace = true
actix-session = { workspace = true, features = ["redis-session"] } actix-session = { workspace = true, features = ["redis-session"] }
actix-web.workspace = true
env_logger.workspace = true env_logger.workspace = true
log.workspace = true log.workspace = true

View File

@ -1,17 +1,17 @@
[package] [package]
name = "db-diesel-async" name = "db-diesel-async"
version = "1.0.0" edition.workspace = true
edition = "2021" rust-version.workspace = true
[features] [features]
postgres_tests = [] postgres_tests = []
[dependencies] [dependencies]
actix-web.workspace = true actix-web = { workspace = true }
diesel = { version = "2", default-features = false, features = ["uuid"] } diesel = { version = "2", default-features = false, features = ["uuid"] }
diesel-async = { version = "0.5", features = ["postgres", "bb8", "async-connection-wrapper"] } diesel-async = { version = "0.5", features = ["postgres", "bb8", "async-connection-wrapper"] }
serde.workspace = true dotenvy = { workspace = true }
uuid.workspace = true env_logger = { workspace = true }
dotenvy.workspace = true log = { workspace = true }
env_logger.workspace = true serde = { workspace = true }
log.workspace = true uuid = { workspace = true }

View File

@ -10,7 +10,9 @@ Basic integration of [Diesel-async](https://github.com/weiznich/diesel_async) us
# on any OS # 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 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 make sure it has successfully started up and is running
```sh ```sh
# on any OS # on any OS
docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}" 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. The database will now be created in your PostgreSQL instance.
```sh ```sh
docker exec -i postgresql psql -U test-user -c "\l" docker exec -i postgresql psql -U test-user -c "\l"
``` ```

View File

@ -1,11 +1,9 @@
use diesel::prelude::*; use diesel::prelude::*;
use diesel_async::{AsyncPgConnection, RunQueryDsl};
use uuid::{NoContext, Timestamp, Uuid}; use uuid::{NoContext, Timestamp, Uuid};
use crate::models; use crate::models;
use diesel_async::AsyncPgConnection;
use diesel_async::RunQueryDsl;
type DbError = Box<dyn std::error::Error + Send + Sync>; type DbError = Box<dyn std::error::Error + Send + Sync>;
// /// Run query using Diesel to find item by uid and return it. // /// Run query using Diesel to find item by uid and return it.

View File

@ -1,13 +1,14 @@
#[macro_use] #[macro_use]
extern crate diesel; extern crate diesel;
use std::{env, io};
use actix_web::{error, get, middleware, post, web, App, HttpResponse, HttpServer, Responder}; use actix_web::{error, get, middleware, post, web, App, HttpResponse, HttpServer, Responder};
use diesel_async::{ use diesel_async::{
pooled_connection::{bb8::Pool, AsyncDieselConnectionManager}, pooled_connection::{bb8::Pool, AsyncDieselConnectionManager},
AsyncPgConnection, AsyncPgConnection,
}; };
use dotenvy::dotenv; use dotenvy::dotenv;
use std::{env, io};
use uuid::Uuid; use uuid::Uuid;
mod actions; mod actions;

View File

@ -1,7 +1,8 @@
use super::schema::items;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
use super::schema::items;
/// Item details. /// Item details.
#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable, Insertable)] #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable, Insertable)]
#[diesel(table_name = items)] #[diesel(table_name = items)]

61
flake.lock generated Normal file
View File

@ -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
}

28
flake.nix Normal file
View File

@ -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
];
};
};
};
}

View File

@ -4,8 +4,8 @@ edition.workspace = true
rust-version.workspace = true rust-version.workspace = true
[dependencies] [dependencies]
actix-web.workspace = true
actix-cors.workspace = true actix-cors.workspace = true
actix-web.workspace = true
async-graphql = "6" async-graphql = "6"
async-graphql-actix-web = "6" async-graphql-actix-web = "6"
env_logger.workspace = true env_logger.workspace = true

View File

@ -4,13 +4,16 @@ _list:
# Format project. # Format project.
[group("lint")] [group("lint")]
fmt: 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 cargo +nightly fmt
fd --type=file --hidden --extension=yml --extension=md --extension=js --exec-batch npx -y prettier --write
# Check project. # Check project.
[group("lint")] [group("lint")]
check: clippy check: && clippy
fd --type=file --hidden --extension=yml --extension=md --extension=js --exec-batch npx -y prettier --check 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. # Run Clippy over workspace.
[group("lint")] [group("lint")]

View File

@ -4,8 +4,8 @@ edition.workspace = true
rust-version.workspace = true rust-version.workspace = true
[dependencies] [dependencies]
actix-web.workspace = true
actix-utils.workspace = true actix-utils.workspace = true
actix-web.workspace = true
env_logger.workspace = true env_logger.workspace = true
log.workspace = true log.workspace = true
minijinja = { version = "2", features = ["loader"] } minijinja = { version = "2", features = ["loader"] }

View File

@ -6,7 +6,7 @@ publish = false
[package.metadata.cargo-machete] [package.metadata.cargo-machete]
ignored = [ ignored = [
"yarte_helpers" # only used as build dependency "yarte_helpers", # only used as build dependency
] ]
[dependencies] [dependencies]

View File

@ -26,5 +26,5 @@ rand.workspace = true
serde.workspace = true serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
tokio-util.workspace = true
tokio-stream = "0.1.8" tokio-stream = "0.1.8"
tokio-util.workspace = true