devenv
devenv copied to clipboard
Feature/treefmt - Integrate treefmt-nix
- Integrates
treefmt-nixinto thedevenvconfiguration. - Updates the documentation to provide detailed guidance on configuring and using
treefmt-nix. - Adds
treefmtto the pre-commit hooks package to ensure consistent code formatting.
Issues Addressed:
- Closes #533
@domenkozar This is the treefmt-nix. Once this and my other PR are in I will raise a PR for the Just runner. That one touches a lot more stuff and integrates directly with treefmt.
@domenkozar He did it successfully!
I'm happy to merge this, but I don't want to use for it devenv itself.
Any movement on getting this merged? This would be amazing to have included in the devenv options by default!
I agree, if someone wants to clean up the PR that would be great
https://github.com/cachix/devenv/pull/1679
I don't have time contribute right now, but I will add my temp solution (based on this PR) for people to use until this feature is added. First add treefmt-nix to the devenv.yml.
{
pkgs,
lib,
config,
inputs,
...
}: let
# Setup a wrapped treefmt
treefmt =
(inputs.treefmt-nix.lib.evalModule pkgs {
projectRootFile = "devenv.nix";
programs = {
alejandra.enable = true; # Nix formatter
rustfmt.enable = true; # Rust formatter
shfmt.enable = true; # Shell script formatter
};
}).config.build;
in {
packages = with pkgs;
[
# Optional: Adds wrapped `treefmt` command to your devshell
treefmt.wrapper
]
++ (lib.attrValues treefmt.programs); # Optional: Adds all the individual formatting programs to your devshell
git-hooks.hooks = {
treefmt = {
enable = true;
description = "Format code with treefmt";
# Important: This overrides the normal binary with the wrapped one that includes your configs
package = treefmt.wrapper;
};
};
}