Share code between scopedImport and import

In addition to reducing duplication, this fixes both import from
derivation and import of derivation for scopedImport