li7y/flake.nix

162 lines
4.4 KiB
Nix
Raw Normal View History

2024-06-24 22:46:04 +02:00
# SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
naersk.url = "github:nix-community/naersk";
git-hooks.url = "github:cachix/git-hooks.nix";
2024-06-24 22:46:04 +02:00
};
outputs = { self, flake-utils, nixpkgs, rust-overlay, naersk, git-hooks }: flake-utils.lib.eachDefaultSystem (system:
2024-06-24 22:46:04 +02:00
let
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default ];
};
rustPackage = pkgs.rust-bin.stable.latest.default;
2024-07-11 01:12:21 +02:00
rustPackageNightly = pkgs.rust-bin.nightly.latest.default;
rustPackageDev = rustPackageNightly;
2024-06-24 22:46:04 +02:00
naersk' = pkgs.callPackage naersk {
rustc = rustPackage;
cargo = rustPackage;
};
in
{
checks = {
pre-commit-check = git-hooks.lib.${system}.run {
2024-06-24 22:46:04 +02:00
src = self;
hooks = {
cargo-check = {
enable = true;
2024-07-11 01:12:21 +02:00
package = rustPackageDev;
2024-06-24 22:46:04 +02:00
};
cargo-deny = {
enable = true;
name = "cargo-deny";
entry = "cargo deny check";
pass_filenames = false;
};
clippy = {
enable = true;
settings = {
denyWarnings = true;
};
2024-06-24 22:46:04 +02:00
packageOverrides = {
2024-07-11 01:12:21 +02:00
cargo = rustPackageDev;
clippy = rustPackageDev;
2024-06-24 22:46:04 +02:00
};
};
nixpkgs-fmt.enable = true;
reuse = {
enable = true;
name = "reuse";
entry = "reuse lint";
pass_filenames = false;
};
rustfmt = {
enable = true;
packageOverrides = {
2024-07-11 01:12:21 +02:00
cargo = rustPackageDev;
rustfmt = rustPackageDev;
2024-06-24 22:46:04 +02:00
};
};
};
};
};
2024-07-25 22:43:58 +02:00
packages =
let
# naersk does not easily allow overrideAttrs
commonNaerskConfigurarion = {
src = self;
checkInputs = with pkgs; [
postgresql
postgresqlTestHook
];
# otherwise the deps derivation is also tested (which just wastes time as there are no tests)
overrideMain = (o: o // {
doCheck = true;
});
2024-07-14 20:51:05 +02:00
2024-07-25 22:43:58 +02:00
# tests need to be able to create and drop databases
postgresqlTestUserOptions = "LOGIN SUPERUSER";
2024-07-14 20:51:05 +02:00
2024-07-25 22:43:58 +02:00
postgresqlTestSetupPost = ''
export DATABASE_URL="postgres://''${PGUSER}/''${PGDATABASE}?port=5432&host=''${PGHOST}"
'';
2024-07-14 20:51:05 +02:00
2024-07-25 22:43:58 +02:00
# Otherwise SQLx tries to infer the databse schema from an empty database
# (as it can only run the migrations once the test binary is built).
# Also, this enforces that the full query cache is included in the repository.
SQLX_OFFLINE = true;
};
in
rec {
li7y = naersk'.buildPackage commonNaerskConfigurarion;
default = li7y;
li7y-tarpaulin = naersk'.buildPackage (commonNaerskConfigurarion // {
name = "li7y-tarpaulin";
checkInputs = commonNaerskConfigurarion.checkInputs ++ (with pkgs; [
cargo-tarpaulin
]);
dontBuild = true;
singleStep = true; # tarpaulin uses different options anyway
cargoTestCommands = _: [ "cargo tarpaulin" ];
postInstall = ''
rm -r $out
cp -r target/tarpaulin $out
'';
});
li7y-oci = pkgs.dockerTools.buildLayeredImage {
name = "li7y";
tag = "latest";
contents = [
li7y
];
config = {
Cmd = [ "${li7y}/bin/li7y" ];
};
2024-07-14 20:51:05 +02:00
};
};
2024-06-24 22:46:04 +02:00
devShells.default = pkgs.mkShell {
buildInputs = [
2024-07-11 01:12:21 +02:00
rustPackageDev
2024-06-24 22:46:04 +02:00
] ++ (with pkgs; [
cargo-deny
2024-07-25 22:43:58 +02:00
cargo-tarpaulin
2024-06-24 22:46:04 +02:00
cargo-watch
clippy
2024-07-22 23:31:11 +02:00
graphviz
2024-07-07 13:45:21 +02:00
postgresql
2024-06-24 22:46:04 +02:00
reuse
sqlx-cli
2024-06-24 22:46:04 +02:00
]);
shellHook = ''
${self.checks.${system}.pre-commit-check.shellHook}
'';
};
});
}