When installing a package with cabal-install, it will also indirectly install all the dependencies. Given a certain package in my .cabal/packages
folder that I didn't directly install, is there a way to find what other package(s) it was a dependency of?

- 68,213
- 24
- 160
- 246
-
1You might also like [this reverse dependencies tool](http://packdeps.haskellers.com/reverse), though it won't be specific to your installed packages. – Daniel Wagner Jan 04 '14 at 23:55
-
btw, the latest `cabal-install` [gained the ability to print depedency information](https://github.com/haskell/cabal/pull/2569) – hvr Jul 19 '15 at 22:32
2 Answers
I found this command somewhere (can't remember where now) and use it regularly to produce a dependency graph of my installed packages:
ghc-pkg dot | tred | dot -Tpng > pkgs.png
Note that it's actually ~/.ghc
which contains the installed package information, rather than ~/.cabal
.
You can also use:
ghc-pkg unregister <pkgname>
which will print a list of packages which would break if you uninstalled this package, which is effectively what you are looking for:
$ ghc-pkg unregister aeson
ghc-pkg: unregistering aeson would break the following packages: criterion-0.8.0.0 yesod-1.2.4 .... (use --force to override)
Update
Using dot -Tsvg > pkgs.svg
in the above command also allows you to use text searches (if you open the file in a browser, for example).
Also, the cab utility is very useful for showing dependencies and reverse dependencies, amongst other things.
For stack users stack dot --external
can be used from your project directory in place of the above ghc-pkg dot
.

- 22,353
- 1
- 72
- 100
-
The resulting graph was a bit messy but `ghc-pkg dot | grep my-package` helped me find what I was looking for. – hugomg Jan 04 '14 at 22:54
-
This is very helpful, thank you. For the benefit of others, I found that if you're doing this in the context of a cabal sandbox, you can use ```cabal sandbox hc-pkg dot``` instead of ```ghc-pkg dot``` – Kris Nuttycombe Jul 03 '15 at 16:52
I found cabal-db to be helpful. For example, you can run
cabal-db revdeps semigroupoids
and it will tell you
zippers: semigroupoids (>=4 && <5)
wl-pprint-extras: semigroupoids (>=3 && <5)
vector-instances: semigroupoids (>=3)
validation: semigroupoids (>=4.0)
transformers-abort: semigroupoids (>=1.2)
these: semigroupoids (>=1.0 && <4.1)
etc...

- 12,409
- 3
- 50
- 87