devenv icon indicating copy to clipboard operation
devenv copied to clipboard

Feature/treefmt - Integrate treefmt-nix

Open UseTheFork opened this issue 1 year ago • 2 comments

  • Integrates treefmt-nix into the devenv configuration.
  • Updates the documentation to provide detailed guidance on configuring and using treefmt-nix.
  • Adds treefmt to the pre-commit hooks package to ensure consistent code formatting.

Issues Addressed:

  • Closes #533

UseTheFork avatar Jul 03 '24 20:07 UseTheFork

@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.

UseTheFork avatar Jul 03 '24 21:07 UseTheFork

@domenkozar He did it successfully!

I-Want-ToBelieve avatar Jul 23 '24 10:07 I-Want-ToBelieve

I'm happy to merge this, but I don't want to use for it devenv itself.

domenkozar avatar Sep 30 '24 12:09 domenkozar

Any movement on getting this merged? This would be amazing to have included in the devenv options by default!

topher097 avatar Nov 20 '24 01:11 topher097

I agree, if someone wants to clean up the PR that would be great

domenkozar avatar Nov 20 '24 16:11 domenkozar

https://github.com/cachix/devenv/pull/1679

domenkozar avatar Jan 22 '25 10:01 domenkozar

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; 
    };
  };
}

giodamelio avatar Aug 29 '25 17:08 giodamelio