The Atatacma desert comprise a very large area of more than 100,000 square kilometers, that host very different climates. The main factors driving the climatic variability are the distance to the Pacific ocean and elevation. This latter factor is very strong, as the Atacama desert covers a formidable elevation range, from sea level to almost 7,000 m, at the summit of Ojos del Salado, the highest volcano in the world.
The highest areas, that also happen to be further of the sea, are the driest and less cloudy. The weather pattern you mention of common foggy conditions only happens very close to the coast, extending inland only about 10 km or a few tens of kilometers trough low lying valleys. And is produced by fog that forms over the sea penetrate inland. It is called camanchaca, but it doesn't cross the coastal mountain range.
The pattern of cloudiness throughout the desert can be visualized using a dataset produced by NASA's Surface meteorology and Solar Energy, in particular the satellite derived Monthly Averaged Clear Sky Days (i.e. cloud cover less than 10%) over a 22-year period (July 1983 - June 2005). It has a resolution of 1°, so about 110 km here. That means that the central area of the desert is covered by just 12 cells, nevertheless it will be enough to see the pattern I mention.
The following figure shows the central section of the Atacama dessert using official IGM 1:500.000 maps in the left. And the mean clear skies dataset on the right for the very same area. The numbers refer to the 22-year mean clear sky days per month.

Now the interpretation will be easier if we overlay those two figures as in one as shown below:

From there you can see how there is a fairly large variability in the amount of clear sky days. From a few at the coast, to about a week over the coastal mountains to about two weeks east of the coastal mountains. Peaking at 17 days per month over the Salar de Atacama (a value surpassed only by the Sahara desert and the interior of Antarctica). Then, it is no coincidence that ALMA observatory, the largest radio telescope in the world, is located there, just east of the salar de Aatacama.
As mentioned before, topography is the main factor controlling this pattern. Even close to the coast, some mountain tops can have remarkable clear sky records, as is the case of the 2,635 m high Mount Paranal were the VLT observatory is located at just 15 km from the coast (falling on the lower left cell with 9 clear sky days in the figure above).
Finally, going back to your question: Both the astronomers and your geography text book are right, but each one is referring to a different area of the Atacama desert. And looking at the above data, it is right to say that the coastal part of the Atacama desert is cloudy most of the year. However, a fairly large area in the interior is cloudless most of the year.