"Copy-on-write" local OPAM switches

Disclaimer: this may already be possible, but it doesn’t seem so from the opam switch documentation.

I use git worktrees pretty heavily in my development cycle. opam switch link is super helpful for this, because I can maintain a main local switch for the master branch and then link it to all the feature branch directories.

The problem comes when I want to install/change a package. Running opam install from the “child” directories modifies the “main” switch, which often causes other branches to fail to build (i.e. API changes, etc.).

I think this could be solved using some “copy-on-write” mechanism, where, if I run opam install on a linked switch, it prompts me if I want to fork the switch in the current directory.

My questions are:

  • Can I do this currently?
  • Would other people find this useful?
  • Is there a better way to do what I’m looking for using existing OPAM semantics?
  • Is this feasible to implement? I’d be more than happy to work on this myself, but I wanted to open up a discussion mostly for the first and second questions.