Restores commit be606eaa87 after it was reverted in e72aa84da1, with an alternative implementation which doesn't require import-from-derivation.
be606eaa87
e72aa84da1