tl;dr: yeah but nah, cabal install --lib
does not install packages in the global packagedb; this is what Setup.hs and cabal v1-install used to do.
Letās give this a go.
I am using GHC 9.4.6, and the global packagedb has mtl-2.2.2 preinstalled.
āÆ ghc-pkg list mtl
/home/andrea/.ghcup/ghc/9.4.6/lib64/ghc-9.4.6/lib/package.conf.d
mtl-2.2.2
Note that a newer version, mtl-2.3.1, is available from Hackage. Letās make a package that declares a dependency on mtl>=2.2.2.
āÆ cabal init --non-interactive --minimal --depend "base,mtl>=2.2.2"
[Log] Using cabal specification: 3.0
[Warning] unknown license type, you must put a copy in LICENSE yourself.
[Log] Creating fresh file CHANGELOG.md...
[Log] Creating fresh directory ./app...
[Log] Creating fresh file app/Main.hs...
[Log] Creating fresh file cabal-global-pkg-db.cabal...
[Warning] No synopsis given. You should edit the .cabal file and add one.
[Info] You may want to edit the .cabal file and add a Description field.
The solver prefers the installed version of mtl-2.2.2
.
āÆ cabal build --dry-run -v3 | grep '^\['
["/home/andrea/.ghcup/ghc/9.4.6/bin/ghc-pkg-ghc-9.4.6","/home/andrea/.ghcup/ghc/9.4.6/bin/ghc-pkg-9.4.6","/home/andrea/.ghcup/ghc/9.4.6/bin/ghc-pkg","/home/andrea/.ghcup/bin/ghc-pkg"]
[__0] trying: cabal-global-pkg-db-0.1.0.0 (user goal)
[__1] trying: base-4.17.2.0/installed-4.17.2.0 (dependency of cabal-global-pkg-db)
[__2] trying: rts-1.0.2/installed-1.0.2 (dependency of base)
[__3] trying: ghc-prim-0.9.1/installed-0.9.1 (dependency of base)
[__4] trying: ghc-bignum-1.3/installed-1.3 (dependency of base)
[__5] trying: mtl-2.2.2/installed-2.2.2 (dependency of cabal-global-pkg-db)
[__6] next goal: transformers (dependency of mtl)
[__6] trying: transformers-0.5.6.2/installed-0.5.6.2
[__7] done
The solver knows that mtl-2.3.1
is available and we can explicictly ask for it.
āÆ cabal build --dry-run -v3 --constraint 'mtl==2.3.1' | grep '^\['
[__0] trying: cabal-global-pkg-db-0.1.0.0 (user goal)
[__1] trying: base-4.17.2.0/installed-4.17.2.0 (dependency of cabal-global-pkg-db)
[__2] trying: rts-1.0.2/installed-1.0.2 (dependency of base)
[__3] trying: ghc-prim-0.9.1/installed-0.9.1 (dependency of base)
[__4] trying: ghc-bignum-1.3/installed-1.3 (dependency of base)
[__5] next goal: mtl (dependency of cabal-global-pkg-db)
[__5] rejecting: mtl-2.2.2/installed-2.2.2 (constraint from command line flag requires ==2.3.1)
[__5] trying: mtl-2.3.1
[__6] next goal: transformers (dependency of mtl)
[__6] trying: transformers-0.5.6.2/installed-0.5.6.2
[__7] done
Now, if I do cabal install --lib mtl-2.3.1
, what happens?
āÆ cabal install --lib mtl-2.3.1
Resolving dependencies...
āÆ ghc-pkg list mtl
/home/andrea/.ghcup/ghc/9.4.6/lib64/ghc-9.4.6/lib/package.conf.d
mtl-2.2.2
Where did it go!?
It turns out I have been wrong all along. cabal install --lib
does not install packages in the global packagedb!
-
./Setup.hs install
would register packages in the global packagedb by default:
-
cabal v1-install
would register packages in the user packagedb (by default, I think you can pass --global
)
- and
cabal install --lib
registers packages in a ghc environment