From 516fdc8f6c649dbccfe15d92b401bf2fa5aaf0d9 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Tue, 26 Apr 2022 20:48:39 +1200 Subject: [PATCH] Add treefmt And use it in place of editorconfig/nixpkgs-fmt checks --- .editorconfig | 24 ------------------------ flake.nix | 30 ++++++++++++------------------ shell.nix | 3 +-- tests/assets/ci.nix | 5 ++--- treefmt.toml | 3 +++ 5 files changed, 18 insertions(+), 47 deletions(-) delete mode 100644 .editorconfig create mode 100644 treefmt.toml diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 1ccb157..0000000 --- a/.editorconfig +++ /dev/null @@ -1,24 +0,0 @@ -# top-most EditorConfig file -root = true - -# Unix-style newlines with a newline ending every file -[*] -charset = utf-8 -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true - -[*.{cc,hh,hpp,pl,pm,sh,t}] -indent_style = space -intend_size = 4 - -[Makefile] -indent_style = tab - -[*.nix] -indent_style = space -indent_size = 2 - -# Match diffs, avoid to trim trailing whitespace -[*.{diff,patch}] -trim_trailing_whitespace = false diff --git a/flake.nix b/flake.nix index ecd3fc8..c15587e 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,7 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs) stdenv; drvArgs = { srcDir = self; }; in rec { @@ -26,25 +27,18 @@ in { - editorconfig = pkgs.runCommand "editorconfig-check" - { - nativeBuildInputs = [ - pkgs.editorconfig-checker - ]; - } '' - editorconfig-checker ${self} - touch $out - ''; + treefmt = stdenv.mkDerivation { + name = "treefmt-check"; + src = self; + nativeBuildInputs = devShells.default.nativeBuildInputs; + dontConfigure = true; - nixpkgs-fmt = pkgs.runCommand "fmt-check" - { - nativeBuildInputs = [ - pkgs.nixpkgs-fmt - ]; - } '' - nixpkgs-fmt --check . - touch $out - ''; + buildPhase = '' + env HOME=$(mktemp -d) treefmt --fail-on-change + ''; + + installPhase = "touch $out"; + }; build = mkVariant pkgs.nix; build-unstable = mkVariant pkgs.nixUnstable; diff --git a/shell.nix b/shell.nix index 4517278..159cd42 100644 --- a/shell.nix +++ b/shell.nix @@ -26,8 +26,7 @@ in nativeBuildInputs = old.nativeBuildInputs ++ [ - pkgs.editorconfig-checker - + pkgs.treefmt pkgs.nixpkgs-fmt (pkgs.python3.withPackages (ps: [ diff --git a/tests/assets/ci.nix b/tests/assets/ci.nix index 150f718..5354be1 100644 --- a/tests/assets/ci.nix +++ b/tests/assets/ci.nix @@ -1,6 +1,5 @@ -{ - pkgs ? import (builtins.getFlake (toString ./.)).inputs.nixpkgs { } - , system ? pkgs.system +{ pkgs ? import (builtins.getFlake (toString ./.)).inputs.nixpkgs { } +, system ? pkgs.system }: { diff --git a/treefmt.toml b/treefmt.toml new file mode 100644 index 0000000..8309d20 --- /dev/null +++ b/treefmt.toml @@ -0,0 +1,3 @@ +[formatter.nix] +command = "nixpkgs-fmt" +includes = ["*.nix"]