ghc-pkg on 8.8.1 with cabal 3.0 does not list user installed packages
Steps to reproduce
Install a package, try to list it with "ghc-pkg list" e.g.
ghc --versionThe Glorious Glasgow Haskell Compilation System, version 8.8.1cabal --versioncabal-install version 3.0.0.0bash-3.2$ cabal install QuickCheckResolving dependencies...Up to dateWarning: You asked to install executables, but there are no executables intarget: QuickCheck. Perhaps you want to use --lib to install librariesinstead.bash-3.2$ cabal install --lib QuickCheckResolving dependencies...Up to datebash-3.2$ ghc-pkg list|fgrep -i Quick
I think this is expected behaviour, at least from the cabal side of things. Version 3.0.0.0 switched to using v2-build by default so installed libraries are now registered into the "default" package environment file in .ghc//environments/default as well as a package-db in .cabal/store/ghc-/package.db which GHC doesn't know about by itself.
AFAICS ghc-pkg simply doesn't have support for listing package environments which sort of kind of makes sense but also breaks this workflow. I think this should be reported as a GHC bug but I'm not sure it would even be a good idea to add pkg-env support to ghc-pkg.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
I don't really think this is a bug in ghc-pkg. It has no concept of these environment files, if you passed the options which were present in the environment file then it would display the package as expected.
Perhaps a solution is for cabal to add a cabal ghc-pkg target which passes the right flags to ghc-pkg to see these "installed" packages.
ok, but it is a change in behaviour from the view point of an end user.
Thanks for responding; from your response, the env file, and the doc I was able to figure out that I now need to type: "ghc-pkg list -f /Users/gcolpitts/.cabal/store/ghc-8.8.1/package.db" Not sure if this change should be in the release notes.
This feels to me like a step backwards from just typing "ghc-pkg list" as the user doesn't have to know anything about package dbs nor their location. Not sure how to go about improving the current state but thanks for your help.
@mpickering Well it's not exactly a bug no, but the question still remains should we maybe teach ghc-pkg about these env files since GHC itself certainly knows about them, so why not the ghc package manager?
Yes, cabal changed its default behaviour and this is the source of the issue. Given that, I hope you agree that this is a high priority feature request. I am very unhappy with cabal 3.0 changes in behaviour; they make using the ghc ecosystem harder to use and are a step backward in my opinion. This is what I meant by regression. I should have clarified that it is a regression in cabal which IMHO necessitates a change in ghc-pkg. I'm just trying to make the ghc ecosystem better and appreciate everyone's help in doing so and getting the issues to the right people.
It is not simply cabal which changed the behavior. The real change is that a raw ghc or ghci will make use of environment files, but ghc-pkg will not, so regardless of how those files are written (via Cabal or otherwise), this is an inconsistency in the ghc toolchain.
I've been trying to get Cabal to work myself. It seems that all that's required for ghc-pkg and the default package environment to play nicely is for there to be a wildcard in the default environment that selects the latest version of all packages that are visible in the package db. Then ghc-pkg can function as before, and code requiring a specific environment can name its requirements.
It would also be nice if Cabal and GHC could both work on the user db. I've told GHC where to find its db for now by saying:
ln -s ~/.cabal/store/ghc-8.6.5/package.db ~/.ghc/x86_64-darwin-8.6.5/package.conf.d
We ran into this today. ghc was reporting it is seeing multiple modules with the same name, but using ghc-pkg we could not see a single user package installed. It took a while to figure out where the packages were coming from. If GHC knows about the packages then why not ghc-pkg? Or there should be some other way to list what packages ghc knows about, a ghc option? or yet another other ghc tool to operate on environment files?
Ok, let me add a suggestion from irc chat here: The base problem is just as described above. It breaks user-expectations for ghc-pkg to not show packages that a raw invocation of ghc or ghci sees. The simplest solution is just for ghc-pkg to detect when there's an env file around, and then, on ghc-pkg list (at least) simply warn that there's such a file, and that file will determine what ghc sees.
Should I submit a doc bug for "If we can't get this fixed for ghc 8.10.2/8.12.1 can we document how to find the packages that have been installed?". Perhaps this is documented in the release notes for 9.0 but I can't find them. From my entry above it seems that is currently:
ghc-pkg list -f $HOME/.cabal/store/ghc-9.0.0.20200925/package.dbghc-pkg list
cabal v1-install is no longer an option as some packages, e.g. pandoc, install with cabal install but not with cabal v1-install
I'm disappointed that it doesn't seem that this will be fixed. I realize that cabal is separate from ghc but from an end users perspective it's all one ecosystem. cabal 3 seems to me very backward incompatible with cabal 2 and ghc.
Just ran into this as well, as I wanted to use ghc-pkg to find out the data-dir of something that I installed. Also, I find ghc-pkg list very useful to understand what ghc sees.
@trac-george.colpitts Do you have an opinion about how this is supposed to behave? An environment file contains not only links to where the package database is but also a list of packages it exposes from one of the package databases.
ghc-pkg currently doesn't understand anything to do with -package flags.
Is it still useful if we just get the visible package databases from the environment file and display everything in the package database (ignoring the package visibility flags?)
IMHO it is supposed to behave the way it used to, i.e. show all the packages I have. Now (in 9.2.2) I have to type two commands to see this, previously "ghc-pkg list" would show all packages. Here are the two commands I now type to see all the packages I have what I want is to see all this by just typing the first command.
@trac-george.colpitts ok, but the output of the second command ignores the visibility settings given by the environment files so you might not be actually able to use all those packages.
Sorry I don't understand all the issues. Is it possible to fix the reported issue, i.e if I install a package I should be able to see the package when I do "ghc-pkg list"? Thanks
I think that the expected behavior would be that the ghc-pkg list should, when making use of an environment file, first, loudly proclaim it is doing such a thing, and second, only list as exposed those packages specified in the environment file.
I.e. its default behavior should be to present the packages to the user the same way they will experience them if they open ghci.
@gershomb, @mpickering in the past I haven't needed to be aware of env files and as far as I know I am not using them. In this case will the fix give me what I want: when I install a package I will see the package when I do "ghc-pkg list"?
@trac-george.colpitts This confusion is exactly why this ticket has not been fixed until now. ghc-pkg is a low level way to interact with package databases, it has commands which allow you to show and modify package databases. As Gershom points out, he would think the expected thing is to see the view that the environment files provides of the the package db, but then what do all the commands which modify a package db do? Modify the database still? Modify the environment file somehow? It's really unclear this feature should exist.
Is the feature you actually want is to see which packages the GHC you have can see by default? It turns out if you have an environment file you can see this by passing -v2 to GHC.. then I see
What I want is for ghc-pkg list to show all packages I have installed.
I have an environment file which ghci seems to be aware of but ghc-pkg is not aware of it. Do I need to set an env variable? i.e. ghc-pkg -v2 list output starts with
ghc-pkg -v2 listGHC package manager version 9.2.2Timestamp 2022-03-10 22:44:08.034359036 UTC for /usr/local/lib/ghc-9.2.2/lib/package.conf.d/package.cacheusing cache: /usr/local/lib/ghc-9.2.2/lib/package.conf.d/package.cachedb stack: ["/usr/local/lib/ghc-9.2.2/lib/package.conf.d"]flag db stack: ["/usr/local/lib/ghc-9.2.2/lib/package.conf.d"]/usr/local/lib/ghc-9.2.2/lib/package.conf.d Cabal-3.6.3.0 (Cabal-3.6.3.0)...
No mention of an env file similar to the one in your output:
Loaded package environment from /home/matt/.ghc/x86_64-linux-8.10.2/environments/default
However ghci is aware of my default env file
ghcighciLoaded package environment from /Users/gcolpitts/.ghc/x86_64-darwin-9.2.2/environments/defaultGHCi, version 9.2.2: https://www.haskell.org/ghc/ :? for help...
I definitely think that any command besides list should not take env files into account. Otherwise tools that interact with ghc-pkg (including cabal itself) might start to have very unexpected behavior.
Its just the case that when there's an env file, list should make the information it provides available to a user, nicely, and in a way that explains what's going on.
The commit which introduced --show-packages (a4cb9a61) states:
commit a4cb9a6173f0af76a32b812c022bbdd76b2abfacAuthor: Duncan Coutts <duncan@well-typed.com>Date: Sun Aug 24 03:38:39 2014 +0100 Add a ghc -show-packages mode to display ghc's view of the package env You can use ghc -show-packages, in addition to any -package -package-conf -hide-package, etc flags and see just what ghc's package info looks like. The format is much like ghc-pkg show. Like the existing verbose tracing, but a specific mode. Re-introduce pretty printed package info (Cabal handled this previously).
So it seems like a bug that it doesn't respect visibility.
This is not going to happen for 9.4.1.. I will remilstone for 9.6.1 but the design needs to be worked out first because as the previous comments show it's really not clear how ghc-pkg should interact with environment files.
@mpickering I don't understand, on reviewing the previous comments, what the outstanding question is.
If you could say what the question is, then this can be cleared up. If it isn't clearly articulated, then it will never be answered, and this issue will be postponed indefinitely
@trac-gershomb indicates that he wants list to take into account environment files and specifically their visibility filter.
ghc-pkg solely understands about package databases (nothing to do with this visibility filter) and extending it to understand the filter seems undesirable.
Therefore I suggested another option which was to add or modify a command which ghc has in order to get ghc to provide an output like ghc-pkg list but can just directly use the logic ghc has for discovering package databases and understanding environment files. That seems like it will solve the root issue of being able to discover which packages GHC knows about?
Ah that's the source of the confusion. The root issue is not simply "being able to discover which packages GHC knows about" but rather that people have been taught for a very long time that the way to do that is ghc-pkg list. So they type ghc-pkg list and get output which is extremely misleading compared to what much documentation still says, and compared to their expectations.
I would be perfectly happy with something as simple as ghc-pkg list figuring out which environment file would be discovered by ghc, and just literally running a "cat" of its contents (appropriately denoted as such) following its current output.
But the issue is really that ghc-pkg list appears to tell users what packages ghc knows about, but that this does not correspond to what will happen when they run ghci and find out what modules are actually in scope. It has been extremely confusing to many users for some years now that this happens, and I'd really like there to be some fix for this. Any command that is not ghc-pkg list no matter how clever or powerful it is will not solve this. But a very crude change that is not at all clever to ghc-pkg listwill solve this.
Any command that is not ghc-pkg list no matter how clever or powerful it is will not solve this. But a very crude change that is not at all clever to ghc-pkg listwill solve this.
I really don't see why a ghc --list-visible-packages flag wouldn't solve this going forward.
It seems the problem is that there is no good way to tell which packages will be in scope. A new ghc --list-visible-packages flag would solve that.
Of course we could do a "crude change" to ghc-pkg list instead. But the result would just be that for the next few years users will still be confused because it will work on new versions but still be broken on old versions.
Users won't be able to rely on ghc-pkg list until everyone is on a fixed version either way. So we might as well use ghc which already has all the logic and add a new properly specified flag there.
I really don't see why a ghc --list-visible-packages flag wouldn't solve this going forward.
Because the problem is that the existing command does not do what people expect, and there is no signpost in the output of that command that it does not do what people expect.
I agree that there will be versions that exist that continue to not do what people expect. However, by that argument, no ux improvement could be made ever, because there will be cases where older versions do not have it.
I agree that users won't be able to rely on it -- however, there are users who have been taught to rely on it and get confused. For those users, improving the immediate situation seems like a straightforward win.
What I'm suggesting seems terribly easy to implement, and has no particular downside. I don't understand the squeamishness.
I agree that --list-visible-packages is a poor solution for the issue at hand, which is specifically that ghc-pkg is misleading. Adding yet another means for the user to query the package database will only further the confusion.
On the other hand, sadly @mpickering is right that there are rather tricky design decisions and architectural issues that make it difficult to resolve this issue in a satisfactory manner. ghc-pkg currently has access to a very small fraction of GHC's package machinery and fixing this would require moving a significant amount of code from ghc into ghc-boot (which ghc-pkg depends upon). Thusfar ghc-pkg has served solely as an interface to GHC's package database. Package visibility (as controlled by -package) is orthogonal to which packages are registered in the package database; rather it has more to do with the module name resolution logic used during compilation.
My tendency is to look for the simplest possible solution in the design space that addresses the underlying problem. Here I would be happy to have logic even that noticed if there was an env file around, and if there was, printed, along with the current output a notice that the packages displayed by list would not correspond to what a ghci session had in scope, due to this env file, and printed the location of the env file so a user could go and read it for themselves.