build(flake): Add treefmt

This only adds this as nix module. So running `nix fmt` will now format
all files under the repo root.

If you want to run this as non-nix user feel free to take a look at the
generated `treefmt.toml`.
This commit is contained in:
Benedikt Peetz 2024-02-19 20:48:50 +01:00
parent 03f8eda241
commit 1b8a33c919
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
2 changed files with 65 additions and 2 deletions

View File

@ -174,7 +174,8 @@
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay", "rust-overlay": "rust-overlay",
"systems": "systems" "systems": "systems",
"treefmt-nix": "treefmt-nix"
} }
}, },
"rust-overlay": { "rust-overlay": {
@ -247,6 +248,26 @@
"repo": "default", "repo": "default",
"type": "github" "type": "github"
} }
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1708335038,
"narHash": "sha256-ETLZNFBVCabo7lJrpjD6cAbnE11eDOjaQnznmg/6hAE=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "e504621290a1fd896631ddbc5e9c16f4366c9f65",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View File

@ -16,7 +16,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# and the Lesser GNU General Public License along with this program. # and the Lesser GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>. # If not, see <https://www.gnu.org/licenses/>.
{ {
description = "A rust crate used to generate multi-language apis for your description = "A rust crate used to generate multi-language apis for your
application"; application";
@ -29,6 +28,13 @@
flake = false; flake = false;
}; };
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
systems = { systems = {
url = "github:nix-systems/default"; url = "github:nix-systems/default";
}; };
@ -64,11 +70,13 @@
}; };
}; };
outputs = { outputs = {
self,
nixpkgs, nixpkgs,
crane, crane,
flake-utils, flake-utils,
rust-overlay, rust-overlay,
ebnf2pdf, ebnf2pdf,
treefmt-nix,
... ...
}: }:
flake-utils.lib.eachDefaultSystem (system: let flake-utils.lib.eachDefaultSystem (system: let
@ -112,18 +120,52 @@
doCheck = true; doCheck = true;
inherit nativeBuildInputs buildInputs; inherit nativeBuildInputs buildInputs;
}; };
treefmtEval = treefmt-nix.lib.evalModule pkgs (
{pkgs, ...}: {
# Used to find the project root
projectRootFile = "flake.nix";
programs = {
alejandra.enable = true;
rustfmt.enable = true;
clang-format.enable = true;
mdformat.enable = true;
shfmt = {
enable = true;
indent_size = 4;
};
shellcheck.enable = true;
};
settings.formatter = {
clang-format = {
options = ["--style" "GNU"];
};
rustfmt = {
# also add the Trixy files
includes = ["*.tri"];
};
};
}
);
in { in {
checks.default = craneBuild; checks.default = craneBuild;
packages = { packages = {
default = craneBuild; default = craneBuild;
}; };
formatter = treefmtEval.config.build.wrapper;
checks = {
formatting = treefmtEval.config.build.check self;
};
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
packages = with pkgs; [ packages = with pkgs; [
alejandra alejandra
cocogitto cocogitto
licensure licensure
treefmt
rust rust
cargo-edit cargo-edit