13720d90bf
This change exposes the already existing wrapper for treefmt/depotfmt that supports running it inside a sandbox. We now reuse it inside //tvix/crate2nix-check, where we previously duplicated the code. The check is now stricter and will also fail on changes, so I had to set the rust edition in the treefmt config. Change-Id: I000e52421258979c038ba6b1f1ff2db14e391b0c Reviewed-on: https://cl.tvl.fyi/c/depot/+/12068 Tested-by: BuildkiteCI Autosubmit: Ilan Joselevich <personal@ilanjoselevich.com> Reviewed-by: flokli <flokli@flokli.de>
65 lines
1.7 KiB
Nix
65 lines
1.7 KiB
Nix
# Builds treefmt for depot, with a hardcoded configuration that
|
|
# includes the right paths to formatters.
|
|
{ depot, pkgs, ... }:
|
|
|
|
let
|
|
# 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
|
|
'';
|
|
|
|
config = pkgs.writeText "depot-treefmt-config" ''
|
|
[formatter.go]
|
|
command = "${depot.nix.buildGo.go}/bin/gofmt"
|
|
options = [ "-w" ]
|
|
includes = ["*.go"]
|
|
|
|
[formatter.tf]
|
|
command = "${terraformat}"
|
|
includes = [ "*.tf" ]
|
|
|
|
[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;
|
|
};
|
|
};
|
|
})
|