Skip to content

Commit

Permalink
refactor(nix): use treefmt support in pre-commit-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
justinrubek committed Apr 30, 2023
1 parent b937ace commit 55defff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
12 changes: 4 additions & 8 deletions flake-parts/formatting.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@
pkgs.rustfmt
];

# wrap treefmt to provide the correct PATH with all formatters
treefmt = pkgs.stdenv.mkDerivation {
treefmt = pkgs.writeShellApplication {
name = "treefmt";
buildInputs = [pkgs.makeWrapper];
buildCommand = ''
makeWrapper \
${pkgs.treefmt}/bin/treefmt \
$out/bin/treefmt \
--prefix PATH : ${lib.makeBinPath formatters}
runtimeInputs = [pkgs.treefmt] ++ formatters;
text = ''
exec treefmt "$@"
'';
};
in {
Expand Down
11 changes: 3 additions & 8 deletions flake-parts/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@
settings = {
src = ../.;
hooks = {
treefmt = {
enable = true;
name = "treefmt";
description = "format the code";
types = ["file"];
pass_filenames = true;
entry = "${self'.packages.treefmt}/bin/treefmt";
};
treefmt.enable = true;
};

settings.treefmt.package = self'.packages.treefmt;
};
};
};
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 55defff

Please sign in to comment.