build(flake): add pre-commit-hook

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-11-17 08:43:04 +01:00
parent 50bd636a64
commit c5c988d465
Signed by: cafkafk
GPG key ID: 26C542FD97F965CE
2 changed files with 31 additions and 3 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@
/result /result
.direnv .direnv
.pre-commit-config.yaml

View file

@ -130,15 +130,42 @@
# For `nix develop`: # For `nix develop`:
devShells.default = pkgs.mkShell { 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` # For `nix flake check`
checks = { 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; formatting = treefmtEval.config.build.check self;
build = packages.check; build = packages.check;
default = packages.default; inherit
test = packages.test; (packages)
default
test
;
lint = packages.clippy; lint = packages.clippy;
}; };
} }