From 6b169db906c701d0941cd6fbdb7f0c9cfb3bb0f7 Mon Sep 17 00:00:00 2001 From: Guanran Wang Date: Sat, 9 Mar 2024 13:30:37 +0800 Subject: [PATCH] flake: use treefmt-nix --- flake.lock | 28 ++++++++++++++++++++++++++-- flake.nix | 19 +++++++++++++++++-- treefmt.nix | 17 +++++++++++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 treefmt.nix diff --git a/flake.lock b/flake.lock index 720dd09..7710cce 100644 --- a/flake.lock +++ b/flake.lock @@ -2,7 +2,9 @@ "nodes": { "flake-utils": { "inputs": { - "systems": "systems" + "systems": [ + "systems" + ] }, "locked": { "lastModified": 1705309234, @@ -37,7 +39,9 @@ "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "systems": "systems", + "treefmt-nix": "treefmt-nix" } }, "systems": { @@ -54,6 +58,26 @@ "repo": "default", "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", diff --git a/flake.nix b/flake.nix index d29feae..4be49a0 100644 --- a/flake.nix +++ b/flake.nix @@ -3,13 +3,25 @@ inputs = { 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: inputs.flake-utils.lib.eachDefaultSystem (system: let inherit (inputs.nixpkgs) lib; pkgs = inputs.nixpkgs.legacyPackages.${system}; + treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs ./treefmt.nix; runtimeDeps = with pkgs; [ # mason / tree-sitter gcc @@ -33,7 +45,10 @@ // {wrapperArgs = ["--prefix" "PATH" ":" "${lib.makeBinPath runtimeDeps}"];}); ### nix fmt - formatter = pkgs.alejandra; + formatter = treefmtEval.config.build.wrapper; + + ### nix flake check + checks = {formatting = treefmtEval.config.build.check inputs.self;}; ### nix develop devShells.default = pkgs.mkShell { diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..249ad8d --- /dev/null +++ b/treefmt.nix @@ -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; +}