flake/dev: use treefmt flake parts module (#1551)

Link: https://github.com/nix-community/stylix/pull/1551

Reviewed-by: Matt Sturgeon <matt@sturgeon.me.uk>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
awwpotato 2025-07-08 10:32:19 -07:00 committed by GitHub
parent 2a1ad27868
commit 8f3259dbc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 77 additions and 86 deletions

View file

@ -4,81 +4,6 @@
./nixpkgs-and-dev-nixpkgs-version-consistency.nix
./packages.nix
./pre-commit.nix
./treefmt.nix
];
perSystem =
{ pkgs, ... }:
{
# TODO: consider using https://flake.parts/options/treefmt-nix.html
formatter = pkgs.treefmt.withConfig {
runtimeInputs = with pkgs; [
# keep-sorted start
biome
keep-sorted
nixfmt-rfc-style
ruff
stylish-haskell
# keep-sorted end
];
settings = {
on-unmatched = "info";
tree-root-file = "flake.nix";
formatter = {
# keep-sorted start block=yes
biome = {
command = "biome";
options = [
"format"
"--write"
"--no-errors-on-unmatched"
"--config-path"
(pkgs.writers.writeJSON "biome.json" {
formatter = {
indentStyle = "space";
indentWidth = 2;
lineWidth = 80;
};
})
];
includes = [
"*.css"
"*.js"
"*.json"
];
excludes = [
# Contains custom syntax that biome can't handle
"modules/swaync/base.css"
];
};
keep-sorted = {
command = "keep-sorted";
includes = [ "*" ];
};
nixfmt = {
command = "nixfmt";
options = [ "--width=80" ];
includes = [ "*.nix" ];
};
ruff = {
command = "ruff";
options = [
"--config"
(pkgs.writers.writeTOML "ruff.toml" {
line-length = 80;
})
"format"
];
includes = [ "*.py" ];
};
stylish-haskell = {
command = "stylish-haskell";
includes = [ "*.hx" ];
};
# keep-sorted end
};
};
};
};
}

View file

@ -44,15 +44,14 @@
# Install git-hooks when activating the shell
shellHook = config.pre-commit.installationScript;
packages =
[
stylix-check
build-and-run-docs
inputs'.home-manager.packages.default
config.formatter
]
++ config.pre-commit.settings.enabledPackages
++ config.formatter.runtimeInputs;
packages = [
stylix-check
build-and-run-docs
inputs'.home-manager.packages.default
config.formatter
] ++ config.pre-commit.settings.enabledPackages;
inputsFrom = [ config.treefmt.build.devShell ];
};
ghc = pkgs.mkShell {

23
flake/dev/flake.lock generated
View file

@ -101,7 +101,28 @@
"dev-nixpkgs": "dev-nixpkgs",
"flake-compat": "flake-compat",
"git-hooks": "git-hooks",
"home-manager": "home-manager"
"home-manager": "home-manager",
"treefmt-nix": "treefmt-nix"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"dev-nixpkgs"
]
},
"locked": {
"lastModified": 1750931469,
"narHash": "sha256-0IEdQB1nS+uViQw4k3VGUXntjkDp7aAlqcxdewb/hAc=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "ac8e6f32e11e9c7f153823abc3ab007f2a65d3e1",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},

View file

@ -46,6 +46,11 @@
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "dev-nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "dev-nixpkgs";
};
# keep-sorted end
};

41
flake/dev/treefmt.nix Normal file
View file

@ -0,0 +1,41 @@
{ inputs, ... }:
{
imports = [ inputs.treefmt-nix.flakeModule ];
perSystem.treefmt = {
projectRootFile = "flake.nix";
programs = {
# keep-sorted start block=yes newline_separated=no
biome = {
enable = true;
settings.formatter = {
indentStyle = "space";
indentWidth = 2;
lineWidth = 80;
};
includes = [
"*.css"
"*.js"
"*.json"
];
excludes = [
# Contains custom syntax that biome can't handle
"modules/swaync/base.css"
];
};
keep-sorted.enable = true;
nixfmt = {
enable = true;
width = 80;
};
ruff-format = {
enable = true;
lineLength = 80;
};
shfmt.enable = true;
stylish-haskell.enable = true;
# keep-sorted end
};
};
}