Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opam install should ignore certain environment variables #5505

Open
Alizter opened this issue Apr 5, 2023 · 1 comment
Open

opam install should ignore certain environment variables #5505

Alizter opened this issue Apr 5, 2023 · 1 comment

Comments

@Alizter
Copy link

Alizter commented Apr 5, 2023

There are certain environment variables that can affect OCaml builds that ideally should be ignored from the global environment and instead provided entirely by opam if they are really needed. These include:

The workarounds to these issues is to simply unset the env var in question, which indicates that the env var could have safely been ignored to begin with.

cc @kit-ty-kate

@kit-ty-kate
Copy link
Member

As a temporary fix, you could modify your config with the following commands:

opam option --global 'wrap-build-commands=[["%{hooks}%/sandbox.sh" "build"] {os = "linux" | os = "macos"} ["env" "-u" "OCAMLPATH" "-u" "OCAMLFIND_DESTDIR"]]'
opam option --global 'wrap-install-commands=[["%{hooks}%/sandbox.sh" "install"] {os = "linux" | os = "macos"} ["env" "-u" "OCAMLPATH" "-u" "OCAMLFIND_DESTDIR"]]'
opam option --global 'wrap-remove-commands=[["%{hooks}%/sandbox.sh" "remove"] {os = "linux" | os = "macos"} ["env" "-u" "OCAMLPATH" "-u" "OCAMLFIND_DESTDIR"]]'

This simply wrap all build/install/remove command with the usual default sandbox followed by env -u of the right environment variables you want to get rid of.

Now for a proper fix to this issue we should probably aim to have a whitelist system for environment variables where most environment variables (except things like PATH and explicitly set variables) are removed and users could add or pass-through specific environment variables using e.g. opam env pass-through OCAMLPARAM. But this is a breakage from previous versions and there are many things to consider (e.g. which environment variables to whitelist by default)

We could also consider a blacklist system to start with but the annoying part is that opam is supposed to be language agnostic (except for select modules in opam-client) so we'd have to route the list of those blacklisted environment variables (i.e. OCAMLPATH and OCAMLFIND_DESTDIR) back through to opam-core somehow. But nothing impossible.

Side note: A similar issue can be traced back to 2012 in #164 which was marked as fixed for opam 0.7.0. The fix back then (155f7f9) consisted in displaying warnings in case select OCAMLFIND_* variables were present (OCAMLPATH wasn't part of it for some reason). Since 2012 this code was removed entirely as far as I can see, but for your case, displaying a warning wouldn't be a solution anyway as those variables are added automatically by Nix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants