tweag / cooked-validators

MIT License
39 stars 11 forks source link

Ormolu fails to build randomly #224

Closed Niols closed 1 year ago

Niols commented 1 year ago

No problem running nix develop on my laptop or on the Tweag builder, but it fails in CI and has failed sometimes inconsistently on @mmontin's machine at least. The logs look like:

error: builder for '/nix/store/34zrwz4lkwm9hhsx39dijc4wr83g7k7l-ormolu-0.5.0.1.drv' failed with exit code 137;
       last 10 log lines:
       > Using tar found on system at:
       > /nix/store/cfbhw8r8ags41vwqaz47r583d0p4h4a1-gnutar-1.34/bin/tar
       > No uhc found
       > building
       > Preprocessing library for ormolu-0.5.0.1..
       > Building library for ormolu-0.5.0.1..
       > [ 1 of 53] Compiling GHC.DynFlags     ( src/GHC/DynFlags.hs, dist/build/GHC/DynFlags.o, dist/build/GHC/DynFlags.dyn_o )
       > [ 2 of 53] Compiling Ormolu.Fixity.Internal ( src/Ormolu/Fixity/Internal.hs, dist/build/Ormolu/Fixity/Internal.o, dist/build/Ormolu/Fixity/Internal.dyn_o )
       > [ 3 of 53] Compiling Ormolu.Fixity    ( src/Ormolu/Fixity.hs, dist/build/Ormolu/Fixity.o, dist/build/Ormolu/Fixity.dyn_o )
       > /nix/store/kmfaajdpyyyg319vfqni5jm9wkxjmf73-stdenv-linux/setup: line 1399:   311 Killed                  ./Setup build
       For full logs, run 'nix log /nix/store/34zrwz4lkwm9hhsx39dijc4wr83g7k7l-ormolu-0.5.0.1.drv'.
error: 1 dependencies of derivation '/nix/store/zmbjd8kaarjfbb7k35il8w8pr88cp7mn-hls-ormolu-plugin-1.0.2.2.drv' failed to build
error: 1 dependencies of derivation '/nix/store/55mjjjl5lbjfpf70g4ffnccalv8jgisx-haskell-language-server-1.8.0.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/50acdysw5y0dxgb8m2qcbp07aydly9yr-nix-shell-env.drv' failed to build

The key thing to notice in here is that:

The issue comes from Ormolu 5.0.1.0 that is a dependency of haskell-language-server 1.8.0.0. Note that this is not nixpkgs's Ormolu at the revision used in our flake. Basically, that version of Ormolu contains a module Ormolu.Fixity that itself contains some Template Haskell generating (my guess) a huge module. This module then takes forever to compile (several minutes on my laptop or the builder) and, more importantly, a lot of memory. As in a loot. As in more than 7GB probably. And this crashes the GitHub Action runner and can cause problem on machines that are also building other things at the same time.

My current “fix” for the CI is to build it locally and send the result to the Cachix server. However, if GC ever collects this derivation, the CI will fail again. Ideally, we would depend on a newer version of Ormolu that doesn't have this issue. It's not easily doable as of today without doing some nasty Nix things.