From ce41414f4ff82867a4dc839d742790f68a6cd54b Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Mon, 24 Mar 2025 11:47:20 +0100 Subject: [PATCH] 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. --- flake.nix | 54 ++++++++++++++++------------------------- nix/checks/clippy.nix | 13 ++++++++++ nix/checks/default.nix | 30 +++++++++++++++++++++++ nix/checks/doc.nix | 12 +++++++++ nix/checks/fmt.nix | 5 ++++ nix/checks/toml-fmt.nix | 11 +++++++++ 6 files changed, 92 insertions(+), 33 deletions(-) create mode 100644 nix/checks/clippy.nix create mode 100644 nix/checks/default.nix create mode 100644 nix/checks/doc.nix create mode 100644 nix/checks/fmt.nix create mode 100644 nix/checks/toml-fmt.nix diff --git a/flake.nix b/flake.nix index 5070907..07aa02c 100644 --- a/flake.nix +++ b/flake.nix @@ -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 diff --git a/nix/checks/clippy.nix b/nix/checks/clippy.nix new file mode 100644 index 0000000..7a5bc32 --- /dev/null +++ b/nix/checks/clippy.nix @@ -0,0 +1,13 @@ +{ + craneLib, + commonArgs, + cargoArtifacts, +}: + +craneLib.cargoClippy ( + commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } +) diff --git a/nix/checks/default.nix b/nix/checks/default.nix new file mode 100644 index 0000000..dd9c5f9 --- /dev/null +++ b/nix/checks/default.nix @@ -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; + }; +} diff --git a/nix/checks/doc.nix b/nix/checks/doc.nix new file mode 100644 index 0000000..7afd451 --- /dev/null +++ b/nix/checks/doc.nix @@ -0,0 +1,12 @@ +{ + craneLib, + commonArgs, + cargoArtifacts, +}: + +craneLib.cargoDoc ( + commonArgs + // { + inherit cargoArtifacts; + } +) diff --git a/nix/checks/fmt.nix b/nix/checks/fmt.nix new file mode 100644 index 0000000..b4db42d --- /dev/null +++ b/nix/checks/fmt.nix @@ -0,0 +1,5 @@ +{ craneLib, src }: + +craneLib.cargoFmt { + inherit src; +} diff --git a/nix/checks/toml-fmt.nix b/nix/checks/toml-fmt.nix new file mode 100644 index 0000000..410fcd8 --- /dev/null +++ b/nix/checks/toml-fmt.nix @@ -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"; +}