about summary refs log tree commit diff
path: root/tools/depotfmt.nix
diff options
context:
space:
mode:
Diffstat (limited to 'tools/depotfmt.nix')
-rw-r--r--tools/depotfmt.nix25
1 files changed, 19 insertions, 6 deletions
diff --git a/tools/depotfmt.nix b/tools/depotfmt.nix
index 8a721492037e..d1a1cb425ae3 100644
--- a/tools/depotfmt.nix
+++ b/tools/depotfmt.nix
@@ -1,6 +1,6 @@
 # Builds treefmt for depot, with a hardcoded configuration that
 # includes the right paths to formatters.
-{ pkgs, ... }:
+{ depot, pkgs, ... }:
 
 let
   config = pkgs.writeText "depot-treefmt-config" ''
@@ -14,8 +14,21 @@ let
     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)
-''
+
+  # 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; }