treefmt-nix icon indicating copy to clipboard operation
treefmt-nix copied to clipboard

mix-format

Open multivac61 opened this issue 4 weeks ago • 3 comments

       > Mix requires the Hex package manager to fetch dependencies
       > Shall I install Hex? (if running non-interactively, use "mix local.hex --force") [Yn] ** (Mix) Could not find an SCM for dependency :castore from TeslaMate.MixProject
       >
       > treefmt: error: formatting failure: formatter '/nix/store/r2bjg78m7b7s75lwcgn69svk010j3sqb-elixir-1.17.3/bin/mix' with options '[format]' failed to apply: exit status 1

To Reproduce

programs.mix-format.enable = true;

and run check on x86_64.

See https://github.com/teslamate-org/teslamate/issues/4294

multivac61 avatar Nov 13 '25 18:11 multivac61

/cc @nifoc

zimbatm avatar Nov 13 '25 19:11 zimbatm

I think I never ran into this because when you're developing, you're forced to install hex (and potentially rebar) and so treefmt always found the ones I manually installed (using the command from the error message above).

Both are packaged in nixpkgs, so theoretically there is no need to download them, but I'm not sure if there is a (good) way to make mix aware of the nix-provided hex. All I can think of is a wrapper shell script, which probably isn't ideal ...

nifoc avatar Nov 14 '25 10:11 nifoc

Yes. I think we need a way to wrap the dependencies into the mix binary for this to be truly useful. There are some popular mix dependencies that influence mix format.

For the time being I added a custom isFormatted check that downloads all the deps at runtime> by wrapping mix. It's not pretty, but it works™

multivac61 avatar Nov 18 '25 10:11 multivac61