jthulhu
jthulhu

Reputation: 8678

Merlin is not picking up dependencies in a nix flake shell

I have a flake containing a dev shell pinning all the dependencies required to develop a given OCaml program, including an actual OCaml compiler, merlin, findlib and the OCaml libraries. For instance, if the project only depended on Graphics, it could be:

devShell = pkgs.mkShell {
    buildInputs = with pkgs; [
        ocaml
    ] ++ (with ocamlPackages; [
        findlib
        merlin
        graphics
    ]);
};

In addition to that, I have direnv setup to use the flake with the following in .envrc:

use flake

And it works fine. If I even add dune (to help finding out where the libraries out) and utop, like

buildInputs = with pkgs; [
    ocaml
    dune_3
] ++ (with ocamlPackages; [
    findlib
    merlin
    graphics
    utop
]);

I can run dune utop, then # open Graphics;; and it still works. After setting up a minimal dune project, dune build just works.

Direnv is also setup for Emacs, so when I edit an OCaml file merlin-mode picks up the shell's merlin flawlessly. Similarly for the shell's utop. But if I add open Graphics, it says "Unbound module Graphics", as if merlin couldn't pick up the dependency.

I've tried following this article, which essentially adds ${merlin}/share/emacs/site-lisp to the load-path in Emacs. But that didn't work.

I've also tried moving to ocaml-lsp+lsp-mode instead of merlin, but that didn't help.

I found this post that describes someone achieving Emacs' integration, but it provided no details on how to achieve that besides configuring ocamlformat, but since it's not in my minimal reproducible example, I don't think it's pertinent.

Upvotes: 1

Views: 147

Answers (0)

Related Questions