  We study the influence of a cosmological population of dense gas clouds on
distant sources, with emphasis on quasar optical variability. In addition to
gravitational lensing such clouds affect flux measurements via refraction in
the neutral gas and via dust extinction, leading to a variety of possible light
curves even in the low optical depth limit. We classify and illustrate the
types of light curves that can arise. For sources as large as quasars we show
that gravitational lensing and extinction are the dominant effects, with gas
refraction playing only a minor role. We find that clouds with mass
~10^{-4.5+/-0.5} M_\odot can reproduce the observed distribution of quasar
variation amplitudes, but only if such clouds make up a large fraction of the
closure density. In that case there may also be substantial extinction of
distant optical sources, which can in principle be constrained by data on
"standard candles" such as type Ia supernovae. Unfortunately that extinction is
essentially grey, even when the material opacity is strongly wavelength
dependent, making it difficult to distinguish from the influence of the
background geometry. We propose a novel statistical test of the origin of
quasar variability, based on the angular structure of the variation timescale
for a large number of quasars distributed all over the sky. If quasar
variability is primarily due to nanolensing that angular structure is expected
to include a quadrupole term of amplitude $\sim5\%$, which ought to be
measurable with future data from the Gaia mission.
