Skip to content

Instantly share code, notes, and snippets.

@frasertweedale
Last active August 8, 2019 03:36
Show Gist options
  • Save frasertweedale/32e929b7afe60fa28c9731f4c3ea473f to your computer and use it in GitHub Desktop.
Save frasertweedale/32e929b7afe60fa28c9731f4c3ea473f to your computer and use it in GitHub Desktop.
unregister dup packages in cabal store

Installing a library explicitly via cabal v2-install lib:blah installs it in the package-db and exposes it. If there are multiple exposed instances of a library available, GHC chooses an unspecified instance (ref). Therefore it is sometimes necessary to manually hide or unregister conflicting versions of packages.

Look for library package-id in cabal install output:

Installing library in /home/ftweedal/.cabal/store/ghc-8.4.4/incoming/new-8790/home/ftweedal/.cabal/store/
ghc-8.4.4/purebred-icu-0.1.0.0-c850b6a0c804167cfc4542bce128a8714de643dcfd6a7114ff42f7e11986c81d/lib

Run ghc-pkg to find all registered packages of the given name:

% ghc-pkg --package-db ~/.cabal/store/ghc-8.4.4/package.db list --verbose purebred-icu            
GHC package manager version 8.4.4 
Timestamp 2019-08-08 02:10:49.304936504 UTC for /home/ftweedal/.cabal/store/ghc-8.4.4/package.db/package.cache 
using cache: /home/ftweedal/.cabal/store/ghc-8.4.4/package.db/package.cache 
Timestamp 2019-05-14 06:58:23.128264739 UTC for /usr/lib64/ghc-8.4.4/package.conf.d/package.cache
using cache: /usr/lib64/ghc-8.4.4/package.conf.d/package.cache
db stack: ["/home/ftweedal/.cabal/store/ghc-8.4.4/package.db","/usr/lib64/ghc-8.4.4/package.conf.d"]
flag db stack: ["/home/ftweedal/.cabal/store/ghc-8.4.4/package.db"]
/home/ftweedal/.cabal/store/ghc-8.4.4/package.db                                                         
    purebred-icu-0.1.0.0 (purebred-icu-0.1.0.0-c850b6a0c804167cfc4542bce128a8714de643dcfd6a7114ff42f7e11986c81d) 
    purebred-icu-0.1.0.0 (purebred-icu-0.1.0.0-dfff5a8c4748d5ee4ab94c008689f30f78a3bf23a528dcf65e8520b89d4064ae)

Unregister or hide the "old" versions of the package:

% ghc-pkg --package-db ~/.cabal/store/ghc-8.4.4/package.db hide --unit-id \
    purebred-icu-0.1.0.0-dfff5a8c4748d5ee4ab94c008689f30f78a3bf23a528dcf65e8520b89d4064ae

Hiding a package makes it unavailable for import (during compilation), but it will continue to work if it is a dependency of some other package. The --unit-id flag is essential. Without it, the hide or unregister operation will ignore the unit hash and affect every instance of the given package and version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment