Opam init when opam.ocaml.org is blocked?

I’m working on setting up a continuous integration (CI) job to build an OCaml application, and as a first step, that job runs opam init. This has turned out to be harder than I realized, because like many enterprise networks, mine blocks open-source download servers including npmjs and PyPI, and requires the use of an internal mirror.

As a temporary workaround while that mirror gets sorted out, I’ve downloaded all upstream dependencies’ tarballs specified in opam-repository, uncompressed them, and opam pinned them, so that when I run dune build on my code, opam builds all upstream dependencies from local sources, without needing to download anything. I’m planning on storing these dependencies’ sources in the local repository as vendored code since opam can’t yet download them itself.

So the only part of the process that I’m blocked on is the initial opam init. I see that I cannot run opam pin unless opam is initialized, which makes sense since the initialization step downloads opam-repository which lets opam know the dependency tree.

I’m hoping you can give me some advice on how to proceed.

I am guessing I can bundle a clone of the entire opam-repository repo with my source, and somehow recreate ~/.opam but that seems flaky (well, flakier than even the above contortions I’m attempting :sweat_smile:). Maybe I can just replicate the opam files for packages that I depend on? Is there some simplification of opam init that I missed in reading the docs?

Thanks for your patience with my unusual use case!

2 Likes

The good news is that your usecase isn’t too unusual :slight_smile: You can set up your own internal mirror very easily by:

  • git clone git://github.com/ocaml/opam-repository
  • use opam admin cache in that checkout (see opam admin cache --help) to download all the upstream distfiles locally.
  • serve that directory over http
  • opam init <your local http server>
9 Likes

There is several way to do it, depending on what you want more exactly.
As @avsm said you can have a local repository with its cache. If you don’t need all packages and you know set of packages, you can filter locally your repository (see opam admin filter) before populating the cache.
If you don’t need a local repository and know by advance needed packages, you can initialise opam with an empty repository and then pin your packages. For the source retrieving part, you can use opam source, or opam-ed if you want to retrieve vcs urls.

1 Like