2021-12-18 14:01:10 +01:00
|
|
|
# Builds treefmt for depot, with a hardcoded configuration that
|
|
|
|
# includes the right paths to formatters.
|
2024-08-19 19:18:40 +02:00
|
|
|
{ pkgs, ... }:
|
2021-12-18 14:01:10 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
config = pkgs.writeText "depot-treefmt-config" ''
|
|
|
|
[formatter.go]
|
2024-08-19 19:18:40 +02:00
|
|
|
command = "${pkgs.go}/bin/gofmt"
|
2021-12-18 14:01:10 +01:00
|
|
|
options = [ "-w" ]
|
|
|
|
includes = ["*.go"]
|
2021-12-24 20:23:00 +01:00
|
|
|
|
2022-01-30 17:05:29 +01:00
|
|
|
[formatter.nix]
|
|
|
|
command = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"
|
|
|
|
includes = [ "*.nix" ]
|
|
|
|
excludes = [
|
2024-03-15 14:42:37 +01:00
|
|
|
"tvix/eval/src/tests/nix_tests/*",
|
2022-01-30 17:05:29 +01:00
|
|
|
]
|
2022-02-07 16:50:07 +01:00
|
|
|
|
|
|
|
[formatter.rust]
|
|
|
|
command = "${pkgs.rustfmt}/bin/rustfmt"
|
2024-07-30 21:35:18 +02:00
|
|
|
options = ["--edition", "2021"]
|
2022-02-07 16:50:07 +01:00
|
|
|
includes = [ "*.rs" ]
|
|
|
|
excludes = [
|
2024-08-24 09:57:45 +02:00
|
|
|
"users/emery/*",
|
2022-02-07 16:50:07 +01:00
|
|
|
"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 ''${@} \
|
2024-07-01 11:47:15 +02:00
|
|
|
--on-unmatched=debug \
|
|
|
|
--config-file=${config} \
|
2021-12-19 19:12:32 +01:00
|
|
|
--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 \
|
2024-07-01 11:47:15 +02:00
|
|
|
--no-cache \
|
|
|
|
--on-unmatched=debug \
|
2021-12-19 19:12:32 +01:00
|
|
|
--fail-on-change \
|
2024-07-01 11:47:15 +02:00
|
|
|
--config-file=${config} \
|
|
|
|
--tree-root=.
|
2021-12-19 19:12:32 +01:00
|
|
|
'';
|
2022-01-30 17:06:58 +01:00
|
|
|
in
|
|
|
|
depotfmt.overrideAttrs (_: {
|
2024-07-30 21:35:18 +02:00
|
|
|
passthru = {
|
|
|
|
inherit config check;
|
|
|
|
meta.ci.extraSteps.check = {
|
|
|
|
label = "depot formatting check";
|
|
|
|
command = check;
|
|
|
|
alwaysRun = true;
|
|
|
|
};
|
2022-01-19 19:23:36 +01:00
|
|
|
};
|
2021-12-28 11:38:03 +01:00
|
|
|
})
|