Ppx_getenv, dune compatible alternative?

I would suggest to send a PR to ppx_optcomp to read the unix environment at condition-evaluation time. For example you could add a new optcomp-time function env_has(var, val) that checks if the variable var is defined in the environment and equal to val, or getenv_or(var, default) – or add support for option types in the interpreter and return a string option to handle undefined variables (more work…).

In any case, I expect that most of the action would be in
https://github.com/janestreet/ppx_optcomp/blob/master/src/interpreter.ml