tarides/opam-monorepo

Add OPAM variable that is set when solver is running

Leonidas-from-XIV opened this issue · 1 comments

It can be helpful to have an OPAM variable that is truthy when it is evaluated by the solver of opam-monorepo and falsy (default) when run with opam.

For context see the discussion here: mirage/mirage#1332

This can be implemented easily once #315 is merged, since then the variables can be passed to the solver without the need of modifying variables in the users switch.

Copying @TheLortex's use case from #289:

Hi, thanks for all the work on opam-monorepo 0.3.

I have been able to implement the changes in the Mirage tool, but there are some changes that would simplify the patch.

Basically, what we want to do is:

  • have a single opam file for switch and monorepo dependencies
  • lock and pull that file using opam-monorepo
  • install the switch dependencies using opam on the opam file

It's a bit different from the current workflow:

  • have a single opam file for switch and monorepo dependencies
  • lock and pull that file using opam-monorepo
  • install the switch dependencies using opam on the lockfile

The problem is that the lockfile is not opam-installable as opam-overlays is temporarily added, so +dune packages are not available. By using a variable in the opam file I'm able to let opam only install the switch dependencies:

depends: [
  "lwt" {switch != "__opam__"}
  "mirage-bootvar-solo5" { >= "0.6.0" & < "0.7.0" & switch != "__opam__" }
  "mirage-clock-solo5" { >= "4.2.0" & < "5.0.0"  & switch != "__opam__"}
  "mirage-logs" { >= "1.2.0" & < "2.0.0"  & switch != "__opam__"}
  "mirage-runtime" { >= "4.0" & < "4.1.0" & switch != "__opam__"}
  "mirage-solo5" { >= "0.8.0" & < "0.9.0" & switch != "__opam__"}
  "mirage" { build & >= "4.0" & < "4.1.0" }
  "ocaml" { build & >= "4.08.0" }
  "ocaml-solo5" { build & >= "0.8.0" }
  "opam-monorepo" { build & >= "0.2.6" }
]

opam-monorepo works as usual. opam install works by passing the OPAMVAR_switch="__opam__" environment variable.