version upgrades can result in bad ghc-pkg database
Task Info (Flyspray) | |
---|---|
Opened By | Doug Patti (dpatti) |
Task ID | 77326 |
Type | Bug Report |
Project | Community Packages |
Category | Packages |
Version | None |
OS | All |
Opened | 2023-01-29 22:56:21 UTC |
Status | Assigned |
Assignee | Felix Yan (felixonmars) |
Details
Description:
The package.cache file that comes packaged with ghc-libs will sometimes not correctly be rebuilt after an install, leaving ghc in a bad state.
Additional information:
I did a system upgrade recently which included the bump from 9.0.2-1 -> 9.0.2-2. When I rebooted, xmonad failed to recompile because of missing dependencies. After a fairly thorough investigation, I realized the cause: on installation, the ghc-libs package writes out a package.cache file in /usr/lib/ghc-9.0.2/package.conf.d/ with the packages that existed at build time. The way ghc-pkg
seems to work is: if all the *.conf files in the directory are older than the package.cache file, it is assumed up-to-date. You can find this in the source code 1, but you can also see this in action in the output of ghc-pkg list -v2
(which increases verbosity):
GHC package manager version 9.0.2
Timestamp 2023-01-05 23:18:48 UTC for /usr/lib/ghc-9.0.2/package.conf.d/package.cache
WARNING: cache is out of date: /usr/lib/ghc-9.0.2/package.conf.d/package.cache
ghc will see an old view of this package db. Use 'ghc-pkg recache' to fix.
Timestamp 2023-01-29 18:31:49.281672821 UTC for /usr/lib/ghc-9.0.2/package.conf.d/vector-0.13.0.0-dBvEOJ9xPHLRlUgE
reading package config: /usr/lib/ghc-9.0.2/package.conf.d/vector-0.13.0.0-dBvEOJ9xPHLRlUgENbcJF.conf
...
You can note that the timestamp in the above output is January 5th, 2023, which is when the ghc-libs-9.0.2-2 package was built. The above output is what I get if I were to re-install ghc-libs at this version right now. However, when I upgraded to 9.0.2-2, the last time I did a system upgrade that resulted in a ghc-register.hook firing (which would have touched some conf file) was 2022-12-31. This meant that when I originally installed ghc-libs-9.0.2-2, it blew away my cache, and because that system upgrade did not contain an update for every haskell library, all the ones that didn't get updated never got re-registered. Those that did get updated were registered, but they often referenced packages that did not exist.
See also FS#77311 FS#77312 which spawned from this confusion.
Steps to reproduce:
I put together a simple repro:
$ sudo touch -m -t 202212311217 /usr/lib/ghc-9.0.2/package.conf.d/*.conf
$ sudo pacman -U ghc-libs-9.0.2-2-x86_64.pkg.tar.zst
$ ghc-pkg list
Note the minimal package list. You can fix with:
$ ghc-pkg recache
$ ghc-pkg list