2021-12-18 14:01:10 +01:00
|
|
|
# Builds treefmt for depot, with a hardcoded configuration that
|
|
|
|
# includes the right paths to formatters.
|
2021-12-19 19:12:32 +01:00
|
|
|
{ depot, pkgs, ... }:
|
2021-12-18 14:01:10 +01:00
|
|
|
|
|
|
|
let
|
2021-12-26 17:06:56 +01:00
|
|
|
# terraform fmt can't handle multiple paths at once, but treefmt
|
|
|
|
# expects this
|
|
|
|
terraformat = pkgs.writeShellScript "terraformat" ''
|
|
|
|
echo "$@" | xargs -n1 ${pkgs.terraform}/bin/terraform fmt
|
|
|
|
'';
|
|
|
|
|
2021-12-18 14:01:10 +01:00
|
|
|
config = pkgs.writeText "depot-treefmt-config" ''
|
|
|
|
[formatter.go]
|
|
|
|
command = "${pkgs.go}/bin/gofmt"
|
|
|
|
options = [ "-w" ]
|
|
|
|
includes = ["*.go"]
|
2021-12-24 20:23:00 +01:00
|
|
|
|
|
|
|
[formatter.tf]
|
2021-12-26 17:06:56 +01:00
|
|
|
command = "${terraformat}"
|
2021-12-24 20:23:00 +01:00
|
|
|
includes = [ "*.tf" ]
|
2022-01-30 17:05:29 +01:00
|
|
|
|
|
|
|
[formatter.nix]
|
|
|
|
command = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"
|
|
|
|
includes = [ "*.nix" ]
|
|
|
|
excludes = [
|
|
|
|
"third_party/nix/tests/*",
|
|
|
|
"third_party/nix/src/tests/*"
|
|
|
|
]
|
2021-12-18 14:01:10 +01:00
|
|
|
'';
|
2021-12-19 19:12:32 +01:00
|
|
|
|
|
|
|
# helper tool for formatting the depot interactively
|
|
|
|
depotfmt = pkgs.writeShellScriptBin "depotfmt" ''
|
|
|
|
exec ${pkgs.treefmt}/bin/treefmt ''${@} \
|
|
|
|
--config-file ${config} \
|
|
|
|
--tree-root $(${pkgs.git}/bin/git rev-parse --show-toplevel)
|
|
|
|
'';
|
|
|
|
|
2021-12-28 11:38:03 +01:00
|
|
|
# wrapper script for running formatting checks in CI
|
|
|
|
check = pkgs.writeShellScript "depotfmt-check" ''
|
2021-12-19 19:12:32 +01:00
|
|
|
${pkgs.treefmt}/bin/treefmt \
|
|
|
|
--fail-on-change \
|
|
|
|
--config-file ${config} \
|
2021-12-28 11:38:03 +01:00
|
|
|
--tree-root .
|
2021-12-19 19:12:32 +01:00
|
|
|
'';
|
2022-01-30 17:06:58 +01:00
|
|
|
in
|
|
|
|
depotfmt.overrideAttrs (_: {
|
2022-01-19 19:23:36 +01:00
|
|
|
passthru.meta.ci.extraSteps.check = {
|
|
|
|
label = "depot formatting check";
|
|
|
|
command = check;
|
|
|
|
alwaysRun = true;
|
|
|
|
};
|
2021-12-28 11:38:03 +01:00
|
|
|
})
|