From 688562bfae07b5fcfa9ab28536af84c98599ea34 Mon Sep 17 00:00:00 2001 From: aleksana Date: Wed, 31 Jul 2024 18:27:54 +0800 Subject: [PATCH] flake: add treefmt-nix --- flake.lock | 23 ++++++++++++++++++++++- flake.nix | 9 ++++++++- treefmt.nix | 10 ++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 treefmt.nix diff --git a/flake.lock b/flake.lock index 21a9a7e86..5b7dcf117 100644 --- a/flake.lock +++ b/flake.lock @@ -71,7 +71,28 @@ "inputs": { "flake-parts": "flake-parts", "flake-root": "flake-root", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722330636, + "narHash": "sha256-uru7JzOa33YlSRwf9sfXpJG+UAV+bnBEYMjrzKrQZFw=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "768acdb06968e53aa1ee8de207fd955335c754b7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 32eafae73..2fcfe2020 100644 --- a/flake.nix +++ b/flake.nix @@ -5,9 +5,14 @@ flake-parts.url = "github:hercules-ci/flake-parts"; flake-root.url = "github:srid/flake-root"; + + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = { nixpkgs, flake-parts, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } { + outputs = { nixpkgs, flake-parts, treefmt-nix, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } { imports = [ inputs.flake-parts.flakeModules.easyOverlay inputs.flake-root.flakeModule @@ -45,6 +50,7 @@ ''; hardeningDisable = [ "fortify" ]; }; + treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix; in { packages.default = nixd; @@ -103,6 +109,7 @@ (import ./nixd/docs/editors/vscodium.nix { inherit pkgs; }) ]; }; + formatter = treefmtEval.config.build.wrapper; }; systems = nixpkgs.lib.systems.flakeExposed; }; diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 000000000..00a70fc3f --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,10 @@ +{ ... }: + +{ + projectRootFile = "flake.nix"; + programs = { + clang-format.enable = true; + nixpkgs-fmt.enable = true; + black.enable = true; + }; +}