We (mostly non-NixOS users) use port-forwarding to connect to private endpoints within our infrastructure. Typically (because of http redirects or applications wanting to be called with a specific host header) we need to call the endpoints by specific DNS names, something like localhost:1234 won’t do. The typical approach to facilitate this is to modify /etc/hosts ad-hoc in some script. This approach doesn’t work in NixOS as /etc/hosts points to some store path and isn’t writeable.
Do you know of a nice way to modify DNS resolution for a specific progress?
Have a look at networking.extraHosts
It is not solving it for specific programs however, but that would not be the case in your previous way of working either?
neworking.extraHosts is what I’ve been doing so far. It works, but it cannot be scripted as easily as a simple grep/sed on /etc/hosts, and adding a line to hosts then requires a rebuild of my system.
You are right, the /etc/hosts solution is unfortunately global instead of specific to certain programs. And finding a solution for that is easily scriptable but changes DNS resolution for the whole system would already be a step forward. But given that I have to find another solution anyway, I might as well aim for a solution that doesn’t change DNS resolution globally on my system.