Issue building OCaml project

I am trying to build an OCaml project using the OCaml packages provided by NixOS. But it is failing with a message saying that a module is missing.

The nix shell file: shell.nix

{ nixpkgs ? import <nixpkgs> {} } :

  inherit (nixpkgs) pkgs;
  ocamlPackages = pkgs.ocamlPackages;

pkgs.mkShell {
  name = "my-ocaml-env";
  buildInputs = [

The dune file (for building): dune

  (name test)

The source code:

type loc = [%import: Lexing.position] [@@deriving show]

let a:loc = Lexing.dummy_pos

let _ = print_endline (show_loc a)

The build output:

$ nix-shell

$ dune build
Entering directory '/alt/programming/ocaml'
File "_none_", line 1:
Error: No implementations provided for the following modules:
         Migrate_parsetree__Migrate_parsetree_versions referenced from /nix/store/107myxypfawcs0mrvcrrmvj6wa4cpgx3-ocaml4.12.0-ppx_import-1.8.0/lib/ocaml/4.12.0/site-lib/ppx_import/ppx_import.cmxa(Ppx_import__Ppx_types_migrate),
         Migrate_parsetree__Migrate_parsetree_driver referenced from /nix/store/107myxypfawcs0mrvcrrmvj6wa4cpgx3-ocaml4.12.0-ppx_import-1.8.0/lib/ocaml/4.12.0/site-lib/ppx_import/ppx_import.cmxa(Ppx_import)

It seems that there is a packaging problem.

Any clues?

cc @vbgl

No idea, sorry. Welcome to the ppx hell…

yeah, might be able to fix this, I’m always looking out for jobs, is the personal or commercial project? just DM me.

Trying to build it at home, I noticed that the dependencies for that derivation include both ocaml-migrate-parsetree-1.8.0 and ocaml-migrate-parsetree-2.1.0. (Enter nix-shell and then examine the OCAMLPATH variable.) I wonder whether ocamlfind is being confused by the multiple versions on the path.

It is an educational project: building a compiler frontend for a toy language.

was it ever working at any point. I see trivia/shell.nix at abe199ce85e870e9a37897d68d5b9a1c990c0aaa · ufop-bcc328/trivia · GitHub is not pinned to any specific version of nixpkgs. So it maybe what ever your version of your system nixpkgs is, maybe causing a problem.

I always pin my nix shells to a specific version.

It is a recent project that never worked with the OCaml packages provided in nixpkgs.

Currently I am installing opam (from nixpkgs) and using opam to install the dependencies of the project. But this may not work when the system is updated. Sometimes I have to reinstall the opam packages, after updating the system.

Is this demo working when using opam with “ppx_deriving>=5.2.1”?
[I suspect Opam is suggesting (which Nix doesn’t do) a different version than Nix. Likely ppx_imports requires an older version of ppx_deriving.)
Certify it works with all packages on latest using opam. If doesn’t work, we have ruled out Nix (for now).
Then, certify all Nix packages used are of same version (ideally latest).

ocaml-migrate-parsetree-2 and ppxlib uses cinaps. Which has an unreleased fix: