about summary refs log tree commit diff
path: root/ops/ci/fmt.nix
blob: a3d697c9810cc544b320668269649fb1fb440dbf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{ pkgs, ... }:
let
  config = pkgs.writeText "depot-treefmt-config" ''
    [formatter.go]
    command = "${pkgs.go}/bin/gofmt"
    includes = ["*.go"]

    [formatter.nix]
    command = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"
    options = [ "--check"]
    includes = [ "*.nix" ]
  '';
in
rec {
  mkFmtScript = src:
    let
      script = pkgs.writeScript "format" ''
        set -euo pipefail
        ROOT=$(${pkgs.git}/bin/git rev-parse --show-toplevel)
        ${pkgs.treefmt}/bin/treefmt --clear-cache --fail-on-change --config-file ${config} --tree-root $ROOT
      '';
    in
    {
      type = "app";
      program = "${script}";
    };
}