Where exactly sys.config.src is parsed and OS env variables replacement takes place?

I mean: in which Erlang module, maybe ERTS C source file etc.? Where is it?

This is done by relx, I believe.

Check relx/priv/templates/extended_bin at bacc278205405f56d2e7b5974b7a59e5ca6f1c70 · erlware/relx · GitHub.

Cheers.