From 2e316499df35053c140ee46819185da8b6fa9d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BChlbacher?= Date: Wed, 22 May 2024 21:35:41 +0200 Subject: [PATCH] build(nix): add treefmt-nix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- flake.lock | 23 ++++++++++++++++++++++- flake.nix | 23 ++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index 2b883b6e..58b8eeb5 100644 --- a/flake.lock +++ b/flake.lock @@ -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" } } }, diff --git a/flake.nix b/flake.nix index 4a2d3c4c..1070466e 100644 --- a/flake.nix +++ b/flake.nix @@ -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; + }; + }; }; }; }