diff options
-rw-r--r-- | flake.nix | 9 | ||||
-rw-r--r-- | ops/ci/fmt.nix | 27 |
2 files changed, 34 insertions, 2 deletions
diff --git a/flake.nix b/flake.nix index 86d32c8..db58906 100644 --- a/flake.nix +++ b/flake.nix @@ -29,7 +29,7 @@ }; # Output config, or config for NixOS system - outputs = { ... }@inputs: + outputs = { self, ... }@inputs: let lib = import ./nix { inherit inputs; }; in { @@ -42,7 +42,9 @@ let pkgs = import inputs.nixpkgs { inherit system; }; home-manager = inputs.home-manager.defaultPackage."${system}"; - in { + ci = import ./ops/ci/fmt.nix { inherit pkgs; }; + in + { packages = pkgs // { inherit home-manager; @@ -58,6 +60,9 @@ }; }; + # `nix run .#ci.format` formats in current directory! + apps.ci.format = ci.mkFmtScript self; + devShell = pkgs.mkShell { buildInputs = with pkgs; [ nixUnstable 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}"; + }; +} |