Import from derivation: Better queries, better errors

This is a new attempt at getting queries to work well with imports from derivations, taking the approach I suggested in the comments on the other PR.  Note that currently the case where 'name' or 'system' require importing from an unrealized derivation (A silly case IMO) is not handled, though that can be easily added.