How does one automatically make an proj.opam file automatically (like ones in python pip freeze > requirements.txt)?

Say I have an opam project that has been sucessfuly installed (either with make, opam or dune). How do I then go ahead to create the proj.opam file automatically so I can easily install it in the future? Is there anything I need to manually do? (e.g. I assume I have to write the build and install myelf…?)


In python we can do pip freeze > requirements.txt if the project is already installed. So perhaps I could:

  1. install the coq proj with make
  2. proceed to do the opam version of pip freeze > requirements.txt.

Is this possible? Ideally fully automatically.

Looking at the doc for pip freeze, I think you are looking for opam lock. opam lock ./proj.opam will generate (or update) a proj.opam.locked file with dependencies versions constraints set to be equal to the installed ones.

1 Like

So there’s multiple options. For specifying the dependencies, it is useful to use dune’s opam generation feature. Then Dune generates you a proper OPAM file. This opam file can then be used with opam lock or opam-monorepo lock to get a reproducible set of dependencies.

what is the dune command that generates my opam file? Thanks!

It is generated automatically when you dune build if you set up the opam integration.

1 Like