{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt.url = "github:numtide/treefmt-nix";
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
advisory-db.url = "github:rustsec/advisory-db";
advisory-db.flake = false;
};
outputs = inputs @ {
flake-parts,
treefmt,
git-hooks,
crane,
advisory-db,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux"];
imports = [
treefmt.flakeModule
git-hooks.flakeModule
];
perSystem = {
config,
pkgs,
lib,
...
}: let
craneLib = crane.mkLib pkgs;
src = craneLib.cleanCargoSource ./.;
commonArgs = {
inherit src;
strictDeps = true;
buildInputs = [] ++ lib.optionals pkgs.stdenv.isDarwin [pkgs.libiconv];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
axum-postgres-tx = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
meta.mainProgram = "axum-postgres-tx";
});
in {
checks = {
inherit axum-postgres-tx;
axum-postgres-tx-clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
axum-postgres-tx-doc = craneLib.cargoDoc (commonArgs // {inherit cargoArtifacts;});
axum-postgres-tx-audit = craneLib.cargoAudit {inherit src advisory-db;};
axum-postgres-tx-deny = craneLib.cargoDeny {inherit src;};
axum-postgres-tx-nextest = craneLib.cargoNextest (
commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
cargoNextestPartitionsExtraArgs = "--no-tests=pass";
}
);
};
packages.default = axum-postgres-tx;
apps.default = {
type = "app";
program = lib.getExe axum-postgres-tx;
meta.description = "";
};
treefmt.programs = {
alejandra.enable = true; # nix
rustfmt.enable = true; # rust
taplo.enable = true; # toml
};
pre-commit.settings.hooks = {
treefmt.enable = true;
treefmt.package = config.treefmt.build.wrapper;
};
devShells.default = craneLib.devShell {
checks = config.checks;
shellHook = ''
${config.pre-commit.installationScript}
'';
packages = with pkgs;
[
rust-analyzer # rust lsp
nil # nix lsp
]
++ config.pre-commit.settings.enabledPackages
++ lib.attrValues config.treefmt.build.programs;
};
};
};
}