build(nix): add treefmt-nix

currently still bare but can be extended with a number of different
formatters (rustfmt, clang-format, ...). For full list see
https://flake.parts/options/treefmt-nix

Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
This commit is contained in:
Thomas Mühlbacher 2024-05-22 21:35:41 +02:00
parent cc16402e4f
commit 2e316499df
2 changed files with 42 additions and 4 deletions

View File

@ -66,7 +66,28 @@
"inputs": { "inputs": {
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1715940852,
"narHash": "sha256-wJqHMg/K6X3JGAE9YLM0LsuKrKb4XiBeVaoeMNlReZg=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "2fba33a182602b9d49f0b2440513e5ee091d838b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
} }
} }
}, },

View File

@ -6,6 +6,11 @@
flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat = { flake-compat = {
url = "github:edolstra/flake-compat"; url = "github:edolstra/flake-compat";
flake = false; flake = false;
@ -17,10 +22,13 @@
self, self,
nixpkgs, nixpkgs,
flake-parts, flake-parts,
treefmt-nix,
flake-compat, flake-compat,
... ...
}: }:
flake-parts.lib.mkFlake { inherit inputs; } { flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ inputs.treefmt-nix.flakeModule ];
# can be extended, but these have proper binary cache support in nixpkgs # can be extended, but these have proper binary cache support in nixpkgs
# as of writing. # as of writing.
systems = [ systems = [
@ -41,13 +49,22 @@
packages.bcachefs-tools-fuse = config.packages.bcachefs-tools.override { fuseSupport = true; }; packages.bcachefs-tools-fuse = config.packages.bcachefs-tools.override { fuseSupport = true; };
formatter = pkgs.nixfmt-rfc-style;
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
inputsFrom = [ config.packages.default ]; inputsFrom = [
config.packages.default
config.treefmt.build.devShell
];
LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib"; LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib";
}; };
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
nixfmt-rfc-style.enable = true;
};
};
}; };
}; };
} }