You can get that behavior locally to a directory by using that --write-ghc-environment-files=always
option I just mentioned. For example you can create a minimal cabal file like this:
cabal-version: 3.0
name: sandbox
version: 0
library
build-depends:
base, megaparsec
And then run cabal build --write-ghc-environment-files=always
. Any subsequent uses of ghc
or ghci
in that directory or subdirectories can now use megaparsec
.
Perhaps cabal could make this workflow a bit easier with dedicated commands and cabal could also make it possible to use this approach for the global default
environment. And with this minimal package format it should also be easy to create a program that adds or removes dependencies from the command line.