Detect if a derivation is running in emulation or is being cross compiled

As explained in my issue I’m interested in adding a flag to my build conditional on whether or not the build is being executed under emulation, or alternatively being cross-compiled.

Is there any mechanism in nixpkgs to determine if there is a cross build happening under emulation? I see that I could accept targetPlatform.config and hostPlatform.config and check if they are the same, is that the best way?

Appreciate input from more experienced nixpkgs users!