about summary refs log tree commit diff
path: root/ops
diff options
context:
space:
mode:
Diffstat (limited to 'ops')
-rw-r--r--ops/ci/fmt.nix27
1 files changed, 27 insertions, 0 deletions
diff --git a/ops/ci/fmt.nix b/ops/ci/fmt.nix
new file mode 100644
index 0000000..a3d697c
--- /dev/null
+++ b/ops/ci/fmt.nix
@@ -0,0 +1,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}";
+    };
+}