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> {} } :

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

pkgs.mkShell {
  name = "my-ocaml-env";
  buildInputs = [
    ocamlPackages.dune_2
    ocamlPackages.findlib
    ocamlPackages.ocaml
    ocamlPackages.ppxlib
    ocamlPackages.ppx_deriving
    ocamlPackages.ppx_import
  ];
}

The dune file (for building): dune

(executable
  (name test)
  (preprocess
    (pps
      ppx_deriving.show
      ppx_import)))

The source code: test.ml

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),
           /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)
         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.

https://github.com/ufop-bcc328/trivia

was it ever working at any point. I see trivia-lexer/shell.nix at abe199ce85e870e9a37897d68d5b9a1c990c0aaa · ufop-bcc328/trivia-lexer · 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:

I “solved” this by overriding ocaml-migrate-parsetree-2 = self.ocaml-migrate-parsetree. Then all dependencies of the project compile, but the project itself fails with
Error: Too many incompatible ppx drivers were found: ppxlib and ocaml-migrate-parsetree.

Maybe there should be an ocaml equivalent of pythonCatchConflictPhase.

The problem here is just package version. When you lock to the proper version it builds and works.
Opam does automatic version management. Nix only does dependency management. So we have to manually enforce the correct version of packages. One or some dependency here has to be downgraded and it will work.

@romildo Is your problem solved?

Hosted by Flying Circus.