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
|
|
|
|
'';
|
|
|
|
|
2022-10-30 22:28:02 +01:00
|
|
|
# TODO: Upgrade to Go 1.19 and reformat tree
|
2021-12-18 14:01:10 +01:00
|
|
|
config = pkgs.writeText "depot-treefmt-config" ''
|
|
|
|
[formatter.go]
|
2022-10-30 22:28:02 +01:00
|
|
|
command = "${pkgs.go_1_18}/bin/gofmt"
|
2021-12-18 14:01:10 +01:00
|
|
|
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 = [
|
2022-08-10 17:53:50 +02:00
|
|
|
"tvix/eval/src/tests/*",
|
2022-01-30 17:05:29 +01:00
|
|
|
]
|
2022-02-07 16:50:07 +01:00
|
|
|
|
|
|
|
[formatter.rust]
|
|
|
|
command = "${pkgs.rustfmt}/bin/rustfmt"
|
|
|
|
includes = [ "*.rs" ]
|
|
|
|
excludes = [
|
|
|
|
"users/tazjin/*",
|
|
|
|
]
|
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 \
|
2022-02-07 21:57:36 +01:00
|
|
|
--clear-cache \
|
2021-12-19 19:12:32 +01:00
|
|
|
--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
|
|
|
})
|