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"; crane.url = "github:ipetkov/crane";
}; };
outputs = outputs =
{ self {
, nixpkgs self,
, flake-utils nixpkgs,
, rust-overlay flake-utils,
, crane rust-overlay,
, crane,
}: }:
flake-utils.lib.eachDefaultSystem ( flake-utils.lib.eachDefaultSystem (
system: system:
@ -25,6 +25,11 @@
allowUnfree = true; allowUnfree = true;
}; };
}; };
# Import rust setup
rustSetup = import ./nix/rust-setup.nix { inherit pkgs crane; };
inherit (rustSetup) rustVersion rustPlatform craneLib;
src = craneLib.cleanCargoSource ./.; src = craneLib.cleanCargoSource ./.;
commonArgs = { commonArgs = {
@ -57,10 +62,6 @@
doCheck = false; doCheck = false;
}; };
# Import rust setup
rustSetup = import ./nix/rust-setup.nix { inherit pkgs crane; };
inherit (rustSetup) rustVersion rustPlatform craneLib;
# Import vault-hier package # Import vault-hier package
vault-hier = import ./nix/packages/vault-hier.nix { vault-hier = import ./nix/packages/vault-hier.nix {
inherit inherit
@ -76,29 +77,16 @@
}; };
in in
{ {
checks = { # Import checks
inherit vault-hier; checks = import ./nix/checks {
inherit
my-workspace-clippy = craneLib.cargoClippy (commonArgs // { craneLib
inherit cargoArtifacts; src
cargoClippyExtraArgs = "--all-targets -- --deny warnings"; commonArgs
}); cargoArtifacts
vault-hier
my-workspace-doc = craneLib.cargoDoc (commonArgs // { pkgs
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";
};
}; };
# Add packages output # 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";
}