flake: use treefmt-nix

This commit is contained in:
Guanran Wang 2024-03-09 13:30:37 +08:00
parent 79fa35d000
commit 6b169db906
Signed by: nyancat
SSH key fingerprint: SHA256:8oWGKciPALWut/6WA27oFKofX+6Wtc0gQnsefXLQx/8
3 changed files with 60 additions and 4 deletions

View file

@ -2,7 +2,9 @@
"nodes": { "nodes": {
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": [
"systems"
]
}, },
"locked": { "locked": {
"lastModified": 1705309234, "lastModified": 1705309234,
@ -37,7 +39,9 @@
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs",
"systems": "systems",
"treefmt-nix": "treefmt-nix"
} }
}, },
"systems": { "systems": {
@ -54,6 +58,26 @@
"repo": "default", "repo": "default",
"type": "github" "type": "github"
} }
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1709911575,
"narHash": "sha256-yC2iOKe0BSZAeXLNPXPrsGn5BwUTYYZESKb+OblLnXY=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "9c57261c71871d2208a6dd4394774cca226c6dbc",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View file

@ -3,13 +3,25 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
### De-dupe flake dependencies
systems.url = "github:nix-systems/default";
}; };
outputs = inputs: outputs = inputs:
inputs.flake-utils.lib.eachDefaultSystem (system: let inputs.flake-utils.lib.eachDefaultSystem (system: let
inherit (inputs.nixpkgs) lib; inherit (inputs.nixpkgs) lib;
pkgs = inputs.nixpkgs.legacyPackages.${system}; pkgs = inputs.nixpkgs.legacyPackages.${system};
treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
runtimeDeps = with pkgs; [ runtimeDeps = with pkgs; [
# mason / tree-sitter # mason / tree-sitter
gcc gcc
@ -33,7 +45,10 @@
// {wrapperArgs = ["--prefix" "PATH" ":" "${lib.makeBinPath runtimeDeps}"];}); // {wrapperArgs = ["--prefix" "PATH" ":" "${lib.makeBinPath runtimeDeps}"];});
### nix fmt ### nix fmt
formatter = pkgs.alejandra; formatter = treefmtEval.config.build.wrapper;
### nix flake check
checks = {formatting = treefmtEval.config.build.check inputs.self;};
### nix develop ### nix develop
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {

17
treefmt.nix Normal file
View file

@ -0,0 +1,17 @@
{
projectRootFile = "flake.nix";
### nix
programs.deadnix.enable = true;
programs.statix.enable = true;
programs.alejandra.enable = true;
### lua
programs.stylua.enable = true;
### toml
programs.taplo.enable = true;
### misc
programs.prettier.enable = true;
}