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