Regarding the possibility of immigration to Spain, I think a lawyer practicing law in that country would be the best person to answer. If you relocate to Portugal, you can come with a D7 and still work as a freelancer or even on an employment contract. Holding passive income does not prevent you from earning active income.
Ask A Question | Learn more about Portugal
How can I retire in Portugal and Spain and freelance from time to time?
I am a UK citizen who has retired early due to health issues. I am considering relocating to Portugal or Spain. However, I may occasionally do some freelancing consulting work. Would this affect my chances of applying for an NLV in Spain or the D7 in Portugal?