Add treefmt

And use it in place of editorconfig/nixpkgs-fmt checks
This commit is contained in:
adisbladis 2022-04-26 20:48:39 +12:00
parent 9482b5ab3e
commit 516fdc8f6c
5 changed files with 18 additions and 47 deletions

View file

@ -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

View file

@ -8,6 +8,7 @@
flake-utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) stdenv;
drvArgs = { srcDir = self; }; drvArgs = { srcDir = self; };
in in
rec { rec {
@ -26,25 +27,18 @@
in in
{ {
editorconfig = pkgs.runCommand "editorconfig-check" treefmt = stdenv.mkDerivation {
{ name = "treefmt-check";
nativeBuildInputs = [ src = self;
pkgs.editorconfig-checker nativeBuildInputs = devShells.default.nativeBuildInputs;
]; dontConfigure = true;
} ''
editorconfig-checker ${self}
touch $out
'';
nixpkgs-fmt = pkgs.runCommand "fmt-check" buildPhase = ''
{ env HOME=$(mktemp -d) treefmt --fail-on-change
nativeBuildInputs = [ '';
pkgs.nixpkgs-fmt
]; installPhase = "touch $out";
} '' };
nixpkgs-fmt --check .
touch $out
'';
build = mkVariant pkgs.nix; build = mkVariant pkgs.nix;
build-unstable = mkVariant pkgs.nixUnstable; build-unstable = mkVariant pkgs.nixUnstable;

View file

@ -26,8 +26,7 @@ in
nativeBuildInputs = old.nativeBuildInputs ++ [ nativeBuildInputs = old.nativeBuildInputs ++ [
pkgs.editorconfig-checker pkgs.treefmt
pkgs.nixpkgs-fmt pkgs.nixpkgs-fmt
(pkgs.python3.withPackages (ps: [ (pkgs.python3.withPackages (ps: [

View file

@ -1,6 +1,5 @@
{ { pkgs ? import (builtins.getFlake (toString ./.)).inputs.nixpkgs { }
pkgs ? import (builtins.getFlake (toString ./.)).inputs.nixpkgs { } , system ? pkgs.system
, system ? pkgs.system
}: }:
{ {

3
treefmt.toml Normal file
View file

@ -0,0 +1,3 @@
[formatter.nix]
command = "nixpkgs-fmt"
includes = ["*.nix"]