See #64258 for more details and some discussion.
Fix #22729.
tl;dr: This fixes the behaviour at run-time but uses "n/a" defaults
inside the Nix build sandbox (build-time).
There might still be a few minor regressions, we might have to tweak
the behaviour over time (e.g. the implementation from Debian also
differs from the original version), and we could refactor the script,
but it should work well enough for now.