flake-modules: add treefmt to fix the 'nix fmt' command

This commit is contained in:
Gaetan Lepage 2024-05-07 16:45:47 +02:00 committed by Gaétan Lepage
parent ba545ded79
commit f7f255afe2
4 changed files with 58 additions and 3 deletions

View file

@ -11,6 +11,7 @@
./templates.nix
./tests.nix
./wrappers.nix
inputs.flake-root.flakeModule
];
perSystem =

View file

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

39
flake.lock generated
View file

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

View file

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