Skip to main content

cabal2nix --compiler Option

My oldest daughter is back to kindergarten from today, though it is only for mornings for a while. I only had a little bit of time available, so I worked on a small task: integrating the hr API changes and HMock tests that I experimented with when I first tried out HMock. The project now has conditionals in the Cabal file, so that the mock tests are only built and run with supported versions of GHC. I therefore removed the Nix configuration, since it does not work with the conditionals. I looked a bit more into possible solutions and found that cabal2nix includes a --compiler option that specifies the “compiler to use when evaluating the Cabal file” and wondered if it could help solve the issue. Unfortunately, it is not even recognizing the option.

Currently, the Nix configuration for my projects makes use of the developPackage function, defined in nixpkgs. This function uses the cabal2nix utility to convert the Cabal file for the package to a Nix derivation, but it notoriously does not support conditionals. I noticed that the developPackage function includes a cabal2nixOptions parameter that “can contain extra command line arguments to pass to cabal2nix when generating the package derivation.”

Checking out the cabal2nix source, I saw a --compiler option that specifies the “compiler to use when evaluating the Cabal file.” I am not sure if it is what I want or not, but I figured that it is worth trying out. I tried various ways to pass the option and always get an error like the following:

$ nix-build
building '/nix/store/83ps2pypqrglw92zdljxbi6wcyi1y67q-cabal2nix-hr.drv'...
installing
Invalid option `--compiler'

Usage: cabal2nix [--version] [--sha256 HASH] [--maintainer MAINTAINER]
                 [--no-haddock] [--hpack | --no-hpack] [--no-check]
                 [--jailbreak] [--benchmark] [--revision ARG]
                 [--no-hyperlink-source] [--enable-library-profiling]
                 [--enable-executable-profiling] [--enable-profiling]
                 [--extra-arguments ARG] [--hackage-db PATH] [--shell]
                 [-f|--flag ARG] [--compiler ARG] [--system ARG]
                 [--subpath PATH] [--hackage-snapshot ARG] URI
                 [--dont-fetch-submodules]

  Recognized URI schemes:

    cabal://pkgname-pkgversion     download the specified package from Hackage
    cabal://pkgname                download latest version of this package from Hackage
    file:///local/path             load the Cabal file from the local disk
    /local/path                    abbreviated version of file URI
    <git/svn/bzr/hg URL>           download the source from the specified repository

  If the URI refers to a cabal file, information for building the package will
  be retrieved from that file, but hackage will be used as a source for the
  derivation. Otherwise, the supplied URI will be used to as the source for the
  derivation and the information is taken from the cabal file at the root of the
  downloaded source.
builder for '/nix/store/83ps2pypqrglw92zdljxbi6wcyi1y67q-cabal2nix-hr.drv' failed with exit code 1
error: build of '/nix/store/83ps2pypqrglw92zdljxbi6wcyi1y67q-cabal2nix-hr.drv' failed

It does not seem to recognize the --compiler option even though the option is listed in the usage information that is displayed! I am out of time, so I shall give up on this.

By the way, I discussed the issue with a friend over the New Year holidays, and he suggested that I resolve it by transforming the output of cabal2nix to make the changes that are appropriate for the version of GHC being used. Perhaps I can do this using a modifier (or perhaps overrides). (I really wish that it was implemented in a better language… Scheme would be a huge improvement, but what I really want is types!) I hope to give this a try soon. Perhaps I will give up on trying to build/test with many versions of GHC when using Nix, at least until I get it working again on a single version.

Author

Travis Cardwell

Published

Tags