Limit memory used by cabal install?

EDIT: the post was unclear about the true issue, so ignore this answer as it was written with something else in mind, but has some useful comments.

I think if you externally limit Cabal's or GHC's memory consumption to 1GB, you will start getting a lot of failed builds due to early terminations by a Linux memory guard (or whatever it's called — somebody, please?). This might not be the case if you find a way to convince Cabal itself to use less memory, and convince GHC to go on a diet, too.

I ran into this just recently while building Curry KiCS2 on a 1GB virtual machine with just 1GB of swap space. (Of course my goal was not to limit memory consumption but instead get the damn thing to finish building, so all I did was increase VM memory to 4GB and swap to 8GB, but that's clearly not what you're after.)

So I think there is probably no workaround to GHC consuming a lot of memory during compilation. Just make sure parallel compilation is turned off though. And research means to reduce GHC's memory consumption, by compilation flags (of GHC itself, possibly), or turn off optimization phases that might consume a lot of memory, etc.

A brighter mind could prove me wrong though.


@reyman64 suggestion confirmed to work on Xubuntu 18.04 with 2GB ram. Thanks! So, cabal install -v cabal-install hangs the system. The following works fine:

cabal install -v --ghc-options='+RTS -M1G -RTS' cabal-install