Ocaml -- buildDunePackage not working in 21.05?

Hi folks,

I have some Ocaml code that I was able to build at the start of the year, but under 21.05 it’s complaining about dune being the wrong version. It’s nothing specific to my code, I can reproduce on unrelated examples.

Let’s use the buildDunePackage example from the 21.05 manual. That example gives a function that returns a derivation for building angstrom. The manual isn’t clear on where buildDunePackage is defined, but it exists in ocamlPackages, as do some of the other function arguments. OK… so, below is the manual example, and an attempt to evaluate it in 21.05:

  # definition straight from the manual...
  angstrom =
    { lib, fetchFromGitHub, buildDunePackage, alcotest, result, bigstringaf }:

    buildDunePackage rec {
      pname = "angstrom";
      version = "0.10.0";

      minimumOCamlVersion = "4.03";

      src = fetchFromGitHub {
        owner = "inhabitedtype";
        repo = pname;
        rev = version;
        sha256 = "0lh6024yf9ds0nh9i93r9m6p5psi8nvrqxl5x7jwl13zb0r9xfpw";

      buildInputs = [ alcotest ];
      propagatedBuildInputs = [ bigstringaf result ];
      doCheck = true;

      meta = with lib; {
        homepage = "https://github.com/inhabitedtype/angstrom";
        description =
          "OCaml parser combinators built for speed and memory efficiency";
        license = licenses.bsd3;
        maintainers = with maintainers; [ sternenseemann ];
# let's call that function, I'm being as explicit as I can...
in let
  rev21_05 = "1f91fd1040667e9265a760b0347f8bc416249da7";
  url = "https://github.com/NixOS/nixpkgs/archive/${rev21_05}.tar.gz";
  pkgs = (import (fetchTarball url) { });
in with pkgs;
with ocamlPackages;
angstrom {
  inherit lib fetchFromGitHub buildDunePackage alcotest result bigstringaf;

Trying to nix-build this, I get the result:

error: dune 1 is not available for OCaml 4.12.0

There’s nothing Dune-1 specific about this example, and I get the exact same error when trying to build my own code. A reduced example, that tries to build an empty source directory and has no build inputs, also fails the same way.

Am I invoking this builder wrong? Is this a regression? Thanks for your help!


Add useDune2 = true; to buildDunePackage. Let me know how it goes.

The documentation should be updated. Likely useDune2 = true; should be the default value.

Thank you! My code is building again. To get the manual example working, I had to:

  • add useDune2 = true
  • bump the angstrom version to "0.15.0" , the most recent release (otherwise it complains about upgrading the project from jbuild to dune)
  • sha256 = "MK8o+iPGANEhrrTc1Kz9LBilx2bDPQt7Pp5P2libucI=";
  • add ocamlPackages.ppx_let to the buildInputs.

I see where the manual source is located, and could do a pull request. But perhaps defaulting useDune2 to true should be decided first. Where’s the right place to discuss that?

add ocamlPackages.ppx_let to the buildInputs.

If your project doesn’t require ppx_let and because your project used angstrom, ppx_let was required (by angstrom), it could mean ppx_let had to be added to angstrom 's propagatedBuildInputs, which right now it is not there. Please check this. If confirmed, you can make a PR adding ppx_let to angstrom’s propagatedBuildInputs.

Where’s the right place to discuss that?

You could open an issue on GitHub. Make sure you ping the active OCaml maintainers, I know of @vbgl and @sternenseemann .

I seldom use Discourse, but if you need any quick help, talk to me on Telegram, just created a Nix OCaml group.

I think this could be done in a single PR and I have also been thinking about doing this in the past.

It’s just annoying work involving:

  1. Identifying all expressions that still use dune 1, set useDune2 = false; explicitly there
  2. Changing the default value of useDune2
  3. Removing all remaining instances of useDune2 = true and possibly also inherit (somepkg) useDune2

Not sure if I’ll get to it in the near future though.

Updating the example in the manual is probably a good idea regardless of if or when we change the default value!

Please check this.

Correct, I only added ppx_let to propagatedBuildInputs because angstrom wouldn’t build without it. [correction – we need ppx_let, but regular buildInputs seems to be enough.] I wasn’t using angstrom in my own code, this was just to get the manual example to build. Thanks for the suggestion re: Github & the maintainers.

Hmm. I’ve just taken a look at the nixpkgs definition of angstrom, and I think the right fix here is just to copy that into the manual example. The issue isn’t that angstrom doesn’t build, it’s just that the example has diverged from the channel.

@sternenseemann – you’re right. I’ve just started PR #127520 to update the manual examples.