# Issue building OCaml project

**URL:** https://discourse.nixos.org/t/issue-building-ocaml-project/13739
**Category:** Help
**Created:** [June 21, 2021, 11:26pm UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739 "2021-06-21T23:26:52Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![romildo](https://discourse.nixos.org/user_avatar/discourse.nixos.org/romildo/32/223_2.png) [@romildo](https://discourse.nixos.org/u/romildo)
#### Post date: [June 21, 2021, 11:26pm UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/1 "2021-06-21T23:26:52Z")

</div>

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`

```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`

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

```

The source code: `test.ml`

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

let a:loc = Lexing.dummy_pos

let _ = print_endline (show_loc a)

```

The build output:

```plaintext
$ 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

---

<div class="post-metadata">

### Author: ![vbgl](https://discourse.nixos.org/user_avatar/discourse.nixos.org/vbgl/32/128_2.png) [@vbgl](https://discourse.nixos.org/u/vbgl)
#### Post date: [June 22, 2021, 7:30am UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/2 "2021-06-22T07:30:30Z")

</div>

No idea, sorry. Welcome to the ppx hell…

---

<div class="post-metadata">

### Author: ![nixinator](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nixinator/32/3859_2.png) [@nixinator](https://discourse.nixos.org/u/nixinator)
#### Post date: [June 22, 2021, 12:35pm UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/3 "2021-06-22T12:35:39Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gmfawcett](https://discourse.nixos.org/user_avatar/discourse.nixos.org/gmfawcett/32/4472_2.png) [@gmfawcett](https://discourse.nixos.org/u/gmfawcett)
#### Post date: [June 22, 2021, 11:33pm UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/4 "2021-06-22T23:33:08Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![romildo](https://discourse.nixos.org/user_avatar/discourse.nixos.org/romildo/32/223_2.png) [@romildo](https://discourse.nixos.org/u/romildo)
#### Post date: [June 24, 2021, 12:52pm UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/5 "2021-06-24T12:52:28Z")

</div>

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

[https://github.com/ufop-bcc328/trivia](https://github.com/ufop-bcc328/trivia)

---

<div class="post-metadata">

### Author: ![nixinator](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nixinator/32/3859_2.png) [@nixinator](https://discourse.nixos.org/u/nixinator)
#### Post date: [June 28, 2021, 1:32pm UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/6 "2021-06-28T13:32:40Z")

</div>

was it ever working at any point. I see [https://github.com/ufop-bcc328/trivia/blob/abe199ce85e870e9a37897d68d5b9a1c990c0aaa/shell.nix](https://github.com/ufop-bcc328/trivia/blob/abe199ce85e870e9a37897d68d5b9a1c990c0aaa/shell.nix) 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.

---

<div class="post-metadata">

### Author: ![romildo](https://discourse.nixos.org/user_avatar/discourse.nixos.org/romildo/32/223_2.png) [@romildo](https://discourse.nixos.org/u/romildo)
#### Post date: [June 28, 2021, 7:34pm UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/7 "2021-06-28T19:34:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![superherointj](https://discourse.nixos.org/user_avatar/discourse.nixos.org/superherointj/32/3589_2.png) [@superherointj](https://discourse.nixos.org/u/superherointj)
#### Post date: [September 30, 2021, 4:17pm UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/8 "2021-09-30T16:17:48Z")

</div>

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:

> <https://github.com/ocaml-ppx/cinaps/commit/2791bce694bfea6ab077f13fc2987fb56fa5006f>
>
> Signed-off-by: Rudi Grinberg \<me@rgrinberg.com\>

---

<div class="post-metadata">

### Author: ![symphorien](https://discourse.nixos.org/user_avatar/discourse.nixos.org/symphorien/32/546_2.png) [@symphorien](https://discourse.nixos.org/u/symphorien)
#### Post date: [October 28, 2021, 8:42am UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/9 "2021-10-28T08:42:04Z")

</div>

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.`

---

<div class="post-metadata">

### Author: ![symphorien](https://discourse.nixos.org/user_avatar/discourse.nixos.org/symphorien/32/546_2.png) [@symphorien](https://discourse.nixos.org/u/symphorien)
#### Post date: [October 28, 2021, 8:48am UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/10 "2021-10-28T08:48:25Z")

</div>

Maybe there should be an ocaml equivalent of pythonCatchConflictPhase.

---

<div class="post-metadata">

### Author: ![superherointj](https://discourse.nixos.org/user_avatar/discourse.nixos.org/superherointj/32/3589_2.png) [@superherointj](https://discourse.nixos.org/u/superherointj)
#### Post date: [November 24, 2021, 8:33am UTC](https://discourse.nixos.org/t/issue-building-ocaml-project/13739/11 "2021-11-24T08:33:56Z")

</div>

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?
