about summary refs log tree commit diff
path: root/tools/depotfmt.nix
blob: 8a721492037e9c633228129f6bd757c713272771 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Builds treefmt for depot, with a hardcoded configuration that
# includes the right paths to formatters.
{ pkgs, ... }:

let
  config = pkgs.writeText "depot-treefmt-config" ''
    [formatter.go]
    command = "${pkgs.go}/bin/gofmt"
    options = [ "-w" ]
    includes = ["*.go"]

    [formatter.tf]
    command = "${pkgs.terraform}/bin/terraform"
    options = [ "fmt" ]
    includes = [ "*.tf" ]
  '';
in pkgs.writeShellScriptBin "depotfmt" ''
  exec ${pkgs.treefmt}/bin/treefmt ''${@} \
    --config-file ${config} \
    --tree-root $(${pkgs.git}/bin/git rev-parse --show-toplevel)
''