Excessive amounts of nicotine on your walls and ceiling will interfere with the primers ability to stick. Sanding won't do you much good. The best thing to do is washing. An example of "Excessive" would be wiping an area with a rag and warm water and discovering that your walls are actually white not yellow.
It is possible to prime without washing, but it does have some risks. Using a low VOC primer will have the most risks. Water based primer will dissolve some of the nicotine stains and allow them to migrate to the surface. This process will be unpredictable and uneven.
Actually, spraying is a good idea. It will lay a thick even coat without agitating the stains. A good primer to try is Zinsser 123 acrylic primer. It dries fast and is thick. You will need to apply 2 coats with 3-4 hours between each coat. You should be able to find a comparable primer in your area. Make sure it dries fast, recoat in one hour, and can seal tannin bleed. Tannin bleed is a similar type of stain.
Using a low VOC primer might not seal out all of the odor.
The best way to deal with this is washing using a strong cleaner, like TSP, and priming with a Tinted Shellac. This will seal out any problematic stains and odors. Unfortunately, this would involve washing and a primer that is all VOC, very smelly.