Cabal: new-install fails with empty store: ghc-pkg: .../package.db: getDirectoryContents:openDirStream: does not exist (No such file or directory)

Created on 11 Aug 2018  路  7Comments  路  Source: haskell/cabal

Invoking cabal new-install fails to initialize the respective store pkg-db if it didn't exist yet; this manifests as e.g.

$ cabal new-install -w ghc-8.6.1 hlint -vnormal+nowrap
cabal: ghc-pkg dump failed: dieVerbatim: user error (cabal: '/opt/ghc/bin/ghc-pkg-8.6.1' exited with an error:
ghc-pkg: /home/hvr/.cabal/store/ghc-8.6.0.20180810/package.db: getDirectoryContents:openDirStream: does not exist (No such file or directory)
)

cc @typedrat


WORKAROUND

For the respective -w argument, invoke

cabal new-repl -w ghc-8.6.1 --build-dep fail

for non-interactive environments, below seems to work:

echo "" | cabal new-repl -w ghc-8.6.1 --build-dep fail

this will build the trivial package fail and initialise the store pkg-db; after this new-install will work.

Yet another workaround suggested in https://github.com/haskell/cabal/issues/5516#issuecomment-424184066 is to create the folder package.db at the location mentioned in the error message.

nix-local-build priority bug

Most helpful comment

FWIW I ran in to this while updating the haskell Docker image (based on upstream ghc-8.6.1 and cabal-install-2.4 Debian packages). I've found that the directory simply needs to exist (i.e. mkdir -p $HOME/.cabal/store/ghc-8.6.1/package.db).

All 7 comments

Raising priority as this was reported to cause problems for users bootstrapping/upgrading to newer versions of cabal-install via new-install

This hit me in CI, where I needed to new-install some stuff into builder image. I workaround it by

    && echo 'cabal-version: 2.2'      > z.cabal \
    && echo 'name: z'                >> z.cabal \
    && echo 'version: 0'             >> z.cabal \
    && echo 'library'                >> z.cabal \
    && echo '  build-depends: aeson' >> z.cabal \
    && cat z.cabal \
    && (cabal new-build || true) \
    && rm -f z.cabal \

The likely place where this is caused is at

https://github.com/haskell/cabal/blob/b07e39fa414b89b18861b060b159625d40ebbf27/cabal-install/Distribution/Client/CmdInstall.hs#L445-L449

Now the question is how to tweak the code to not choke; a missing store pkg-db index folder in this codepath ought to be handled the same as if it was empty...

Just a +1 from me on addressing this sooner. I was bit by this as I upgraded to GHC 8.6.1 and honestly there was no indication whatsoever what the resolution might be. The workaround @phadej described worked for me, though I can't claim I understand why or how.

Perhaps at least advertise how to resolve this more widely?

FWIW I ran in to this while updating the haskell Docker image (based on upstream ghc-8.6.1 and cabal-install-2.4 Debian packages). I've found that the directory simply needs to exist (i.e. mkdir -p $HOME/.cabal/store/ghc-8.6.1/package.db).

There appears no release for this fix yet, although it is quite an important one.

There appears no release for this fix yet, although it is quite an important one.

cabal-install-2.4.1.0 includes this fix.

Was this page helpful?
0 / 5 - 0 ratings