I asked this question on the mailing list a couple weeks ago, but I didn鈥檛 get a response, so I鈥檓 asking it here, instead. I am wondering what the proper procedure is to safely remove an installed package on recent versions of stack. I鈥檇 like to do this for two reasons:
Sometimes I鈥檇 like to clean out old packages for old snapshots I no longer care about.
I am currently trying to reproduce a bug in stack, and I think it may depend on package installation order. It鈥檚 very painful to have to blow everything away every time I want to try a different installation order.
On older versions of stack, I鈥檇 just delete the relevant subdirectories in the ~/.stack/snapshots directory, but (1) that鈥檚 harder to do now that those directories don鈥檛 have human-readable names and (2) it seems that deleting those directories leaves something somewhere in an invalid state (due to the source of truth being the pantry database?) that I do not know how to fix without blowing all of ~/.stack away and starting over.
Is there a way to do this? I鈥檇 very much like to reproduce the aforementioned bug, since I鈥檝e hit it a couple times, and it鈥檚 a real showstopper.
Thanks for raising the issue. It's been a while since I looked at pantry stuff; from some limited investigation I suspect there's still no ready tool.
@qrilka what do you think?
Unfortunately currently I don't think we have a good way to resolve this. While discussing some possible ways to implement GC for ~/.stack there was an idea to track last time of access for a particular package in a snapshot but there is nothing like that in the code base so that needs to be implemented. In the current version we have only files on a file system and you can't do much with only file creation times.
In that case, I have a different but related question, since maybe this is an XY problem. Let鈥檚 say something somehow goes wrong while building a package (from Hackage), and I want to ask stack to rebuild it. Do I currently have no other choice than to blow away the entirety of ~/.stack?
It's hard to say without clear picture about what "goes wrong". But if somehow you get a package incorrectly built and registered then to force its rebuild you could use a hack stack exec ghc-pkg <broken-package> (with extra flags if you need those).
Similar to what Kirill said, to remove an offending package - I use the unregister sub-command from the directory where I tried to build it:
stack exec -- ghc-pkg unregister <broken-pkg>
@psibi thanks so much! you just saved me from the dreaded 2 hours feedback loop and made Haskell and stack viable options again! I also had to remove some .dylib files in my ~/.stack for the trick to work. Next time I need it - I'll document all the steps.
Most helpful comment
In that case, I have a different but related question, since maybe this is an XY problem. Let鈥檚 say something somehow goes wrong while building a package (from Hackage), and I want to ask
stackto rebuild it. Do I currently have no other choice than to blow away the entirety of~/.stack?