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
|
|
|
|
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]
|
|
|
|
command = "${pkgs.terraform}/bin/terraform"
|
|
|
|
options = [ "fmt" ]
|
|
|
|
includes = [ "*.tf" ]
|
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)
|
|
|
|
'';
|
|
|
|
|
|
|
|
# wrapper for running formatting checks in CI
|
|
|
|
check = pkgs.runCommandNoCC "depotfmt-check" {} ''
|
|
|
|
${pkgs.git}/bin/git clone ${depot.path.origSrc} depot
|
|
|
|
export HOME="$(${pkgs.coreutils}/bin/realpath .)"
|
|
|
|
${pkgs.treefmt}/bin/treefmt \
|
|
|
|
--fail-on-change \
|
|
|
|
--config-file ${config} \
|
|
|
|
--tree-root depot && : > $out
|
|
|
|
'';
|
|
|
|
in depotfmt // depot.nix.readTree.drvTargets { inherit check; }
|