linear-base icon indicating copy to clipboard operation
linear-base copied to clipboard

Provide Ormolu via Nix

Open aspiwack opened this issue 3 years ago • 6 comments

Ormolu has very slow to build dependencies (essentially ghc-lib-parser). This has been an obstacle to contributing, and makes the CI very slow on the first push of a new branch.

Currently, the ./format script build Ormolu itself, via stack build. This is convenient (calling ./format is machine independent). The main reason why we went this route back then, was that the version of Ormolu that was available on Nixpkgs was too old, we needed a recent one. Now, I believe that it should be easy to provide Ormolu via Nixpkgs.

This doesn't prevent contributors who want to provide Ormolu via Stack to call stack build ormolu && stack exec -- ./format. It makes the management of dependencies more package-manager agnostic. And will let us download cached Ormolu when using Nix (in particular on CI).

aspiwack avatar Oct 24 '22 16:10 aspiwack

I happened to want a recent ormolu from nixpkgs in some other place, and I found that I had to do this with ghc-9.2.5 to get a recent enough ghc-lib-parser (which meant rebuilding ghc-lib-parser again):

    ormolu = (prev.haskell.packages.ghc925.override {
      overrides = hfinal: hprev: with prev.haskell.lib; {
        ormolu = hprev.generateOptparseApplicativeCompletions [ "ormolu" ]
          (enableSeparateBinOutput hfinal.ormolu_0_5_0_1);
      };
    }).ormolu.bin;

So ormolu-from-nixpkgs may not dodge the ghc-lib-parser build.

endgame avatar Dec 14 '22 05:12 endgame

Indeed, I've noticed something like this in a project of mine recently.

But for CI at least, we can workaround this by setting up a Cachix cache. Which doesn't have the issue that Github actions seem to have that the first build on a PR doesn't use the cache (or maybe that's an issue with our configuration, but I've checked and it looks good. Obviously I may have missed something and there may be an easy solution, it would be great in the short term).

aspiwack avatar Dec 14 '22 07:12 aspiwack

Why don't you just use https://github.com/mrkkrp/ormolu-action ?

mrkkrp avatar Dec 15 '22 08:12 mrkkrp

@mrkkrp AFAIR, we wanted for the same ormolu version to be provided both to the user and to the CI. Which the github action wouldn't help to do, right?

tbagrel1 avatar Dec 15 '22 14:12 tbagrel1

Depends on how badly you want this and whether you want to make a compromise. I usually just use the same ormolu I have on my system for all formatting, and I don't particularly care about its version. I use the GitHub action for all projects on CI. The advantage is that the CI setup is very simple and acts as the definite source of truth, which is all I want. In all my projects it's been really rare, if ever, that my system ormolu would format differently from the CI version. In 99.99% of cases you won't have to reformat, and the benefit is simplicity and reliability.

mrkkrp avatar Dec 15 '22 16:12 mrkkrp

I'll let @aspiwack decide then :)

tbagrel1 avatar Dec 16 '22 08:12 tbagrel1