tvl-depot/tools/depotfmt.nix
Vincent Ambo 3530841a13 chore(tools/depotfmt): remove terraform fmt
This adds almost a gigabyte of closure size for formatting files that almost
never change.

I'll look into building just the formatter somehow, but it's not a very high
priority task.

Change-Id: Ib0f841e1a98133381c5ae154e2a57df8af52dc1f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12293
Tested-by: BuildkiteCI
Reviewed-by: emery <emery@dmz.rs>
Autosubmit: tazjin <tazjin@tvl.su>
2024-08-23 16:13:19 +00:00

55 lines
1.4 KiB
Nix

# Builds treefmt for depot, with a hardcoded configuration that
# includes the right paths to formatters.
{ pkgs, ... }:
let
config = pkgs.writeText "depot-treefmt-config" ''
[formatter.go]
command = "${pkgs.go}/bin/gofmt"
options = [ "-w" ]
includes = ["*.go"]
[formatter.nix]
command = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"
includes = [ "*.nix" ]
excludes = [
"tvix/eval/src/tests/nix_tests/*",
]
[formatter.rust]
command = "${pkgs.rustfmt}/bin/rustfmt"
options = ["--edition", "2021"]
includes = [ "*.rs" ]
excludes = [
"users/tazjin/*",
]
'';
# helper tool for formatting the depot interactively
depotfmt = pkgs.writeShellScriptBin "depotfmt" ''
exec ${pkgs.treefmt}/bin/treefmt ''${@} \
--on-unmatched=debug \
--config-file=${config} \
--tree-root $(${pkgs.git}/bin/git rev-parse --show-toplevel)
'';
# wrapper script for running formatting checks in CI
check = pkgs.writeShellScript "depotfmt-check" ''
${pkgs.treefmt}/bin/treefmt \
--no-cache \
--on-unmatched=debug \
--fail-on-change \
--config-file=${config} \
--tree-root=.
'';
in
depotfmt.overrideAttrs (_: {
passthru = {
inherit config check;
meta.ci.extraSteps.check = {
label = "depot formatting check";
command = check;
alwaysRun = true;
};
};
})