From f7f255afe22fcca0c07177c3707fd61fa0c85835 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Tue, 7 May 2024 16:45:47 +0200 Subject: [PATCH] flake-modules: add treefmt to fix the 'nix fmt' command --- flake-modules/default.nix | 1 + flake-modules/dev/default.nix | 15 ++++++++++++-- flake.lock | 39 ++++++++++++++++++++++++++++++++++- flake.nix | 6 ++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/flake-modules/default.nix b/flake-modules/default.nix index 788aec62..3938193d 100644 --- a/flake-modules/default.nix +++ b/flake-modules/default.nix @@ -11,6 +11,7 @@ ./templates.nix ./tests.nix ./wrappers.nix + inputs.flake-root.flakeModule ]; perSystem = diff --git a/flake-modules/dev/default.nix b/flake-modules/dev/default.nix index bfb5b647..c372400c 100644 --- a/flake-modules/dev/default.nix +++ b/flake-modules/dev/default.nix @@ -2,13 +2,24 @@ { imports = [ inputs.pre-commit-hooks.flakeModule + inputs.treefmt-nix.flakeModule ./devshell.nix ]; perSystem = - { pkgs, ... }: + { pkgs, config, ... }: { - formatter = pkgs.nixfmt-rfc-style; + formatter = config.treefmt.build.wrapper; + + treefmt.config = { + inherit (config.flake-root) projectRootFile; + package = pkgs.treefmt; + + programs = { + nixfmt-rfc-style.enable = true; + statix.enable = true; + }; + }; pre-commit = { settings.hooks = { diff --git a/flake.lock b/flake.lock index 8fb1c168..e2c1b1fe 100644 --- a/flake.lock +++ b/flake.lock @@ -71,6 +71,21 @@ "type": "github" } }, + "flake-root": { + "locked": { + "lastModified": 1713493429, + "narHash": "sha256-ztz8JQkI08tjKnsTpfLqzWoKFQF4JGu2LRz8bkdnYUk=", + "owner": "srid", + "repo": "flake-root", + "rev": "bc748b93b86ee76e2032eecda33440ceb2532fcd", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "flake-root", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -215,10 +230,12 @@ "devshell": "devshell", "flake-compat": "flake-compat", "flake-parts": "flake-parts", + "flake-root": "flake-root", "home-manager": "home-manager", "nix-darwin": "nix-darwin", "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks" + "pre-commit-hooks": "pre-commit-hooks", + "treefmt-nix": "treefmt-nix" } }, "systems": { @@ -250,6 +267,26 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1714058656, + "narHash": "sha256-Qv4RBm4LKuO4fNOfx9wl40W2rBbv5u5m+whxRYUMiaA=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "c6aaf729f34a36c445618580a9f95a48f5e4e03f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index a37338ff..d57115d0 100644 --- a/flake.nix +++ b/flake.nix @@ -16,10 +16,16 @@ url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; }; + # A flake-parts module for finding the project root directory + flake-root.url = "github:srid/flake-root"; devshell = { url = "github:numtide/devshell"; inputs.nixpkgs.follows = "nixpkgs"; }; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";