Pandoc: Document instructions for scripting in Haskell with Cabal 3.0

Created on 14 Jan 2020  Â·  4Comments  Â·  Source: jgm/pandoc

Cabal 3.0 changes the default install subcommand to the new-style installation (aka v2-install in earlier versions). The new-style installation seems not to register any installed packages with the GHC package database. As a result, you can't write Pandoc scripts in Haskell and build them with ghc --make; you would have to set up a full Cabal project for each script, which is rather a drag.

Is this worth documenting somewhere? Pandoc users may want to be aware that they need to use v1- style subcommands in order to get to a working setup for scripting.


The only way I've been able to make this work is to go back to the v1-install subcommand:

$ cabal v1-install pandoc
$ ghc-pkg list pandoc
/Users/elliott/.brew/Cellar/ghc/8.8.1/lib/ghc-8.8.1/package.conf.d
    (no packages)
/Users/elliott/.ghc/x86_64-darwin-8.8.1/package.conf.d
    pandoc-2.9.1.1
$ ghc --make behead.hs 
[1 of 1] Compiling Main             ( behead.hs, behead.o )
Linking behead ...

Whereas whenever I build with any of the new-style commands, I can't build scripts afterwards.

$ cabal install --lib pandoc
$ ghc-pkg list pandoc
.../ghc/8.8.1/lib/ghc-8.8.1/package.conf.d
    (no packages)
$ ghc --make behead.hs 
Loaded package environment from /Users/elliott/.ghc/x86_64-darwin-8.8.1/environments/default
[1 of 1] Compiling Main             ( behead.hs, behead.o )

behead.hs:4:1: error:
    Ambiguous module name ‘Text.Pandoc’:
      it was found in multiple packages: pandoc-2.9.1.1 pandoc-2.9.1.1
  |
4 | import Text.Pandoc
  | ^^^^^^^^^^^^^^^^^^

And similarly with --global:

$ cabal install --global --lib pandoc
$ ghc-pkg list pandoc
.../ghc/8.8.1/lib/ghc-8.8.1/package.conf.d
    (no packages)
$ ghc --make behead.hs 
Loaded package environment from /Users/elliott/.ghc/x86_64-darwin-8.8.1/environments/default
[1 of 1] Compiling Main             ( behead.hs, behead.o )

behead.hs:4:1: error:
    Ambiguous module name ‘Text.Pandoc’:
      it was found in multiple packages: pandoc-2.9.1.1 pandoc-2.9.1.1
  |
4 | import Text.Pandoc
  | ^^^^^^^^^^^^^^^^^^

I'm not sure what exactly is wrong with the new-style subcommands. --global sounds like it should do what I want, but it doesn't seem to. Other users of cabal seem to be having similar issues, see e.g. https://github.com/haskell/cabal/issues/6478.

Note: To be sure I'm getting a clean environment, I run rm -rf ~/.cabal ~/.ghc/x86_64-darwin-8.8.1 && cabal user-config update && cabal update prior to each attempt.

Most helpful comment

Ok, thanks to some discussion on the other issue, I found a set of new-style Cabal commands that seems to work:

cabal v2-install pandoc
cabal v2-install --lib pandoc
cabal v2-install --lib pandoc-types
ghc -package-env=default --make behead.hs

You need the second line to expose Pandoc as a library, and the third because otherwise any dependencies of pandoc-the-library are marked as hidden. (And you need to repeat the third line for any other dependencies you intend to use.)

I still think it's worth some amount of documentation to guide Pandoc users in the right direction, though I guess there's some question whether that should be v1-* or v2-* commands.

All 4 comments

Ok, thanks to some discussion on the other issue, I found a set of new-style Cabal commands that seems to work:

cabal v2-install pandoc
cabal v2-install --lib pandoc
cabal v2-install --lib pandoc-types
ghc -package-env=default --make behead.hs

You need the second line to expose Pandoc as a library, and the third because otherwise any dependencies of pandoc-the-library are marked as hidden. (And you need to repeat the third line for any other dependencies you intend to use.)

I still think it's worth some amount of documentation to guide Pandoc users in the right direction, though I guess there's some question whether that should be v1-* or v2-* commands.

thanks a lot. I was wondering about this myself.

See if the changes in ebf413cdec8157b96db0e510bc0c15a9e8adf0e3 help.

Yes, I those instructions look good to me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ocehugo picture ocehugo  Â·  3Comments

transientsolutions picture transientsolutions  Â·  3Comments

RLesur picture RLesur  Â·  3Comments

eins78 picture eins78  Â·  5Comments

johnridesabike picture johnridesabike  Â·  4Comments