{
description = "Request-scoped PostgreSQL transactions for axum.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt.url = "github:numtide/treefmt-nix";
treefmt.inputs.nixpkgs.follows = "nixpkgs";
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
rust.url = "github:juspay/rust-flake";
rust.inputs.nixpkgs.follows = "nixpkgs";
advisory-db.url = "github:rustsec/advisory-db";
advisory-db.flake = false;
};
outputs = inputs @ {
flake-parts,
advisory-db,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
debug = false;
imports = with inputs; [
treefmt.flakeModule
git-hooks.flakeModule
rust.flakeModules.default
rust.flakeModules.nixpkgs
];
systems = inputs.nixpkgs.lib.systems.flakeExposed;
perSystem = {
config,
pkgs,
...
}: let
inherit (config.rust-project) crane-lib src crates;
in {
packages.default = crates.axum-postgres-tx.crane.outputs.packages.axum-postgres-tx;
checks = {
inherit (crates.axum-postgres-tx.crane.outputs.packages) axum-postgres-tx axum-postgres-tx-doc;
cargo-audit = crane-lib.cargoAudit {inherit src advisory-db;};
cargo-deny = crane-lib.cargoDeny {inherit src;};
integration-test = crane-lib.cargoTest {
inherit src;
pname = "axum-postgres-tx";
cargoExtraArgs = "-p axum-postgres-tx";
strictDeps = true;
cargoArtifacts = crane-lib.buildDepsOnly {
inherit src;
pname = "axum-postgres-tx";
cargoExtraArgs = "-p axum-postgres-tx";
strictDeps = true;
};
cargoTestExtraArgs = "-p axum-postgres-tx --features integration --test integration -- --test-threads=1";
nativeCheckInputs = [pkgs.postgresql];
preCheck = ''
export PGDATA=$TMPDIR/postgresql
export PGHOST=$TMPDIR/run/postgresql
export PGUSER=test_user
export PGDATABASE=test_db
mkdir -p $PGHOST
initdb --encoding=UTF8 -U postgres
echo "unix_socket_directories = '$PGHOST'" >> $PGDATA/postgresql.conf
pg_ctl start -l $PGDATA/logfile
createuser -U postgres $PGUSER
createdb -U postgres -O $PGUSER $PGDATABASE
'';
postCheck = ''
pg_ctl stop
'';
};
};
treefmt.programs = {
alejandra.enable = true;
rustfmt.enable = true;
taplo.enable = true;
taplo.settings.formatting.align_entries = true;
taplo.settings.formatting.column_width = 120;
taplo.settings.formatting.reorder_keys = false;
taplo.settings.rule = [
{
include = ["**/Cargo.toml" "Cargo.toml"];
keys = ["dependencies" "workspace.dependencies"];
formatting.reorder_keys = true;
}
];
};
pre-commit.settings.package = pkgs.prek;
pre-commit.settings.settings.rust.check.cargoDeps =
pkgs.rustPlatform.importCargoLock {lockFile = ./Cargo.lock;};
pre-commit.settings.hooks = {
clippy.enable = true;
clippy.packageOverrides.cargo = crane-lib.cargo;
clippy.packageOverrides.clippy = crane-lib.clippy;
convco.enable = true;
nil.enable = true;
treefmt.enable = true;
trufflehog.enable = true;
};
devShells.default = pkgs.mkShell {
inputsFrom = [config.treefmt.build.devShell config.pre-commit.devShell config.devShells.rust];
packages = with pkgs; [nixd tombi cargo-audit cargo-deny cargo-nextest];
};
};
};
}