formatting: add pre-commit hook to dev shell

This commit is contained in:
DavHau
2023-07-28 18:12:31 +02:00
parent 461bd84205
commit cb307f761a
6 changed files with 145 additions and 5 deletions

View File

@@ -3,9 +3,10 @@
, ...
}: {
imports = [
inputs.pre-commit-hooks-nix.flakeModule
inputs.treefmt-nix.flakeModule
];
perSystem = { pkgs, ... }: {
perSystem = { pkgs, config, ... }: {
treefmt.projectRootFile = "flake.nix";
treefmt.flakeCheck = true;
treefmt.flakeFormatter = true;
@@ -36,5 +37,16 @@
];
includes = [ "*.py" ];
};
# activated in devShells via inputsFrom = [config.pre-commit.devShell];
pre-commit.settings.hooks.format-all = {
name = "format-all";
enable = true;
pass_filenames = true;
entry = toString (pkgs.writeScript "treefmt" ''
#!${pkgs.bash}/bin/bash
${config.treefmt.build.wrapper}/bin/treefmt --clear-cache --fail-on-change "$@"
'');
};
};
}