tweag / opam-nix

Turn opam-based OCaml projects into Nix derivations
MIT License
111 stars 33 forks source link

Adding dependences to dune project #63

Closed undyamon closed 11 months ago

undyamon commented 11 months ago

Describe the bug This might just be me being absolutely new to the OCaml scene, but I don't seem to be able to add new dependences to a dune project. For reference, I'm following the official Getting Started guide.

To Reproduce On a machine that has never seen any Ocaml software, I did the following

mkdir ocamltest
cd ocamltest
git init
nix flake init -t github:tweag/opam-nix#multi-package
git add .
cd ..
dune init proj ocamltest
cd ocamltest
git add .
dune build

Then I edited bin/dune to include dream as a dependency.

(executable
 (public_name ocamltest)
 (name main)
 (libraries ocamltest dream))

and finally

git add bin/dune
exit
nix develop

This puts me in an environment that does not have dream available (dune build fails).

Expected behavior By reading this intro I was expecting the flake to be able to figure out the dependencies by looking at the project. What am I doing wrong? Did I miss something?

Environment x86_64 GNU/Linux NixOS

undyamon commented 11 months ago

Ok I think I finally figured this out. The OCaml tutorial doesn't mention it but it seems like dependencies needs to be defined in the dune-project file as well. Then using buildDuneProject instead of buildOpamProject' automatically generates the .opam file that the flake needs to know which dependencies to install.

Is this all there is to know on the matter?

balsoft commented 11 months ago

Yep, indeed you are supposed to add your dependencies to some file that opam-nix reads. It doesn't read any of the dune files, since dune is a build system and not a package manager (mostly). The way you described should work, another possibility is adding the dependency to your <project>.opam file (if you have such).

undyamon commented 11 months ago

Makes sense, thank you!