From c5c988d465ab112154fe20ad509ada7e6c368276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Fri, 17 Nov 2023 08:43:04 +0100 Subject: [PATCH] build(flake): add pre-commit-hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- .gitignore | 1 + flake.nix | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1cda34f..48bc82e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /result .direnv +.pre-commit-config.yaml diff --git a/flake.nix b/flake.nix index 17b0df1..64cef38 100644 --- a/flake.nix +++ b/flake.nix @@ -130,15 +130,42 @@ # For `nix develop`: devShells.default = pkgs.mkShell { - nativeBuildInputs = with pkgs; [rustup toolchain just convco]; + inherit (self.checks.${system}.pre-commit-check) shellHook; + nativeBuildInputs = with pkgs; [ + rustup + toolchain + just + convco + powertest.packages.${pkgs.system}.default + ]; }; # For `nix flake check` checks = { + pre-commit-check = let + # some treefmt formatters are not supported in pre-commit-hooks we filter them out for now. + toFilter = + # This is a nice hack to not have to manually filter we should keep in mind for a future refactor. + # (builtins.attrNames pre-commit-hooks.packages.${system}) + ["yamlfmt"]; + filterFn = n: _v: (!builtins.elem n toFilter); + treefmtFormatters = pkgs.lib.mapAttrs (_n: v: {inherit (v) enable;}) (pkgs.lib.filterAttrs filterFn (import ./treefmt.nix).programs); + in + pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = + treefmtFormatters + // { + convco.enable = true; # not in treefmt + }; + }; formatting = treefmtEval.config.build.check self; build = packages.check; - default = packages.default; - test = packages.test; + inherit + (packages) + default + test + ; lint = packages.clippy; }; }