add flake checks and formatter, run some formatters

This commit is contained in:
cy 2025-05-11 00:32:41 -04:00
parent ce0e70f95a
commit 112654f448
4 changed files with 41 additions and 19 deletions

View file

@ -11,8 +11,15 @@
};
};
outputs = inputs@{ nixpkgs, flake-utils, crane, ... }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
inputs@{
nixpkgs,
flake-utils,
crane,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
@ -21,13 +28,12 @@
];
};
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain(_: toolchain);
craneLib = (crane.mkLib pkgs).overrideToolchain (_: toolchain);
lib = pkgs.lib;
# don't clean cpp files
cppFilter = path: _type: builtins.match ".*(cpp|hpp)$" path != null;
cppOrCargo = path: type:
(cppFilter path type) || (craneLib.filterCargoSources path type);
cppOrCargo = path: type: (cppFilter path type) || (craneLib.filterCargoSources path type);
src = lib.cleanSourceWith {
src = ./.;
filter = cppOrCargo;
@ -53,11 +59,33 @@
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
nixcp = craneLib.buildPackage (commonArgs // {
nixcp = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
});
}
);
in
{
checks = {
# clippy with all warnings denied
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
# check formatting
cargoFmt = craneLib.cargoFmt {
inherit src;
};
tomlFmt = craneLib.taploFmt {
src = lib.sources.sourceFilesBySuffices src [ ".toml" ];
};
};
devShells.default = craneLib.devShell {
inputsFrom = [ nixcp ];
@ -71,6 +99,8 @@
];
};
formatter = pkgs.nixfmt-rfc-style;
packages.default = nixcp;
}
);

View file

@ -1,9 +1,4 @@
[toolchain]
channel = "nightly"
profile = "minimal"
components = [
"rust-src",
"rust-analyzer",
"rustfmt",
"clippy",
]
components = ["rust-src", "rust-analyzer", "rustfmt", "clippy"]

View file

@ -1,2 +0,0 @@

View file

@ -3,7 +3,6 @@ use std::path::PathBuf;
use clap::{Args, Parser, Subcommand};
mod bindings;
mod cli;
pub mod make_nar;
pub mod path_info;
pub mod push;