refactor: modularize checks into separate Nix files

- Extracted checks (clippy, doc, fmt, and toml-fmt) into modularized Nix files under `nix/checks`.
- Updated `flake.nix` to import checks from the new modularized structure.
- Improved clarity and maintainability by separating concerns for each check.
This commit is contained in:
Harald Hoyer 2025-03-24 11:47:20 +01:00
parent 28ad7cc65c
commit ce41414f4f
6 changed files with 92 additions and 33 deletions

View file

@ -6,12 +6,12 @@
crane.url = "github:ipetkov/crane";
};
outputs =
{ self
, nixpkgs
, flake-utils
, rust-overlay
, crane
,
{
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
}:
flake-utils.lib.eachDefaultSystem (
system:
@ -25,6 +25,11 @@
allowUnfree = true;
};
};
# Import rust setup
rustSetup = import ./nix/rust-setup.nix { inherit pkgs crane; };
inherit (rustSetup) rustVersion rustPlatform craneLib;
src = craneLib.cleanCargoSource ./.;
commonArgs = {
@ -57,10 +62,6 @@
doCheck = false;
};
# Import rust setup
rustSetup = import ./nix/rust-setup.nix { inherit pkgs crane; };
inherit (rustSetup) rustVersion rustPlatform craneLib;
# Import vault-hier package
vault-hier = import ./nix/packages/vault-hier.nix {
inherit
@ -76,29 +77,16 @@
};
in
{
checks = {
inherit vault-hier;
my-workspace-clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
my-workspace-doc = craneLib.cargoDoc (commonArgs // {
inherit cargoArtifacts;
});
# Check formatting
my-workspace-fmt = craneLib.cargoFmt {
inherit src;
};
my-workspace-toml-fmt = craneLib.taploFmt {
src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ];
# taplo arguments can be further customized below as needed
# taploExtraArgs = "--config ./taplo.toml";
};
# Import checks
checks = import ./nix/checks {
inherit
craneLib
src
commonArgs
cargoArtifacts
vault-hier
pkgs
;
};
# Add packages output

13
nix/checks/clippy.nix Normal file
View file

@ -0,0 +1,13 @@
{
craneLib,
commonArgs,
cargoArtifacts,
}:
craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
)

30
nix/checks/default.nix Normal file
View file

@ -0,0 +1,30 @@
{
craneLib,
src,
commonArgs,
cargoArtifacts,
vault-hier,
pkgs,
}:
{
inherit vault-hier;
my-workspace-clippy = import ./clippy.nix {
inherit craneLib commonArgs cargoArtifacts;
};
my-workspace-doc = import ./doc.nix {
inherit craneLib commonArgs cargoArtifacts;
};
# Check formatting
my-workspace-fmt = import ./fmt.nix {
inherit craneLib src;
};
my-workspace-toml-fmt = import ./toml-fmt.nix {
inherit craneLib src;
lib = pkgs.lib;
};
}

12
nix/checks/doc.nix Normal file
View file

@ -0,0 +1,12 @@
{
craneLib,
commonArgs,
cargoArtifacts,
}:
craneLib.cargoDoc (
commonArgs
// {
inherit cargoArtifacts;
}
)

5
nix/checks/fmt.nix Normal file
View file

@ -0,0 +1,5 @@
{ craneLib, src }:
craneLib.cargoFmt {
inherit src;
}

11
nix/checks/toml-fmt.nix Normal file
View file

@ -0,0 +1,11 @@
{
craneLib,
src,
lib,
}:
craneLib.taploFmt {
src = lib.sources.sourceFilesBySuffices src [ ".toml" ];
# taplo arguments can be further customized below as needed
# taploExtraArgs = "--config ./taplo.toml";
}