ocaml / opam

opam is a source-based package manager. It supports multiple simultaneous compiler installations, flexible package constraints, and a Git-friendly development workflow.
https://opam.ocaml.org
Other
1.25k stars 361 forks source link

Looks for _opam even if OPAMROOT and OPAM_SWITCH_PREFIX are set #5358

Open glondu opened 2 years ago

glondu commented 2 years ago

Starting a few months back (I don't know exactly what triggered this), my development environment (which uses Opam (but no _opam) + Dune + Emacs + Merlin) started to freeze regularly (and annoyingly) and it took me time to figure out what was happening.

It turns out that commands like opam var bin look for a directory named _opam in all directories up to /, and the lookup at some level is slow (a few seconds) because of a network filesystem. However, in my environment, OPAMROOT and OPAM_SWITCH_PREFIX are set, so there should be no need to look for _opam.

Is there a way to disable this behaviour?

kit-ty-kate commented 1 year ago

Would setting OPAMSWITCH – automatically added when calling eval $(opam env --set-switch) – work as a temporary workaround in your case?

OPAMROOT only sets the "global working directory" for opam so it’s rather unrelated to switches in general, and OPAM_SWITCH_PREFIX is a little different from OPAMSWITCH: it shows the path to the global switch you currently have set in the environment, but opam itself might detect that you’re currently in a local switch and override that variable for its execution (switching to a local switch is automatic so that’s why you’re seeing all those checks for _opam directories).

Now, I'm not sure what could be improved more systematically here. We could add an option to disable the automatic local switch detection but it introduces other issues that might be worse for usability. We can't just lookup at the list of local switches already added either because opam supports the automatic import of local switches too. Does anyone have an idea?

glondu commented 1 year ago

Would setting OPAMSWITCH – automatically added when calling eval $(opam env --set-switch) – work as a temporary workaround in your case?

I found another workaround (autofs-specific) in the meantime. But setting OPAMSWITCH seems to disable the annoying behaviour indeed.

Now, I'm not sure what could be improved more systematically here. We could add an option to disable the automatic local switch detection but it introduces other issues that might be worse for usability. We can't just lookup at the list of local switches already added either because opam supports the automatic import of local switches too. Does anyone have an idea?

Maybe not cross filesystem boundaries when looking for _opam?