Issues using opam .locked files

Here’s what I’m trying to do:

  • I have a local project (arm) with a my_project.opam.locked
  • I’m copying all config files to a docker/podman container (amd64): *.opam* dune-project dune Makefile*
  • I run opam install --yes --locked --deps-only -- . with the expectation of getting a 1:1 build env as my local project

The first error was that arm-amd64 dependencies were included in locked files (Cross compile and opam lock files with conflicting dependencies - #2 by kit-ty-kate), which seems fixed

I’m getting the following error:

The following dependencies couldn't be met:
  - my_project -> ocaml-system = 5.2.1
      unmet availability conditions: sys-ocaml-version = "5.2.1" & (os != "win32"
    | sys-ocaml-libc = "msvc")

even though opam switch list is:

5.2     ocaml-base-compiler.5.2.1  5.2

and ocam --version is The OCaml toplevel, version 5.2.1

I’m not sure what to make out of this error?
(opam install . --deps-only runs fine)

Is there an alternative to opam .locked files?

It looks like the system you locked the project on was using a preinstalled version of OCaml 5.2.1 (so the .locked file contains a reference to ocaml-system version 5.2.1 instead of ocaml-base-compiler 5.2.1).

It’s another manifestation of the weakness of the current lockfile implementation - the workaround here would be either to edit the lock file to replace the ocaml-system package with ocaml-base-compiler or to re-create the lockfile on a system where you’re using ocaml-base-compiler instead of the preinstalled compiler.

What is the difference between ocaml system and ocaml base compiler?
on the host machine the switch from which the lock file is generated is:

→  /Users/my_user/my_project ocaml-system.5.2.1
 ocaml-base-compiler = 5.2.1 | ocaml-system = 5.2.1

The difference is whether the compiler is provided by your system (e.g. in /usr/bin) and just used by OCaml or whether it’s built from sources and installed in the switch (in $(opam var bin)).

On the host, you should be able to change it with opam switch set-invariant ocaml-base-compiler.5.2.1 which should then build the compiler (and will rebuild the entire switch with it) and then if you recreate the lock then it should use ocaml-base-compiler.5.2.1 instead of ocaml-system.5.2.1.

In the Octez repository, the script which updates the lock file actually removes the definition of the ocaml-system package so that Opam cannot use it. This is only possible because the script actually clones the opam repository (see lines 52-72).