Drying of water from a porous medium is a complex process involving coupled capillary flows, phase change and vapour transport. If there are impurities, such as dissolved salts or suspended particles, in the water, these are transported and concentrated by the drying flow, and deposit or precipitate in the pore space. Understanding where these impurities accumulate and deposit is important in many applications including filtration, salt weathering, and soil salinisation. We formulate a continuum model for this process, coupling the drying dynamics to the impurity transport and deposition. We identify the parameter regime for which the system can be decoupled, so that the drying is independent of the impurity, and analyse a reduced model for the impurity transport and deposition in this case. As expected, we find that impurity is drawn to the surface of the porous medium by the capillary flow, and accumulates in a thin advection-diffusion boundary layer at the surface of the porous medium. However, we show that the thickness of this boundary layer is comparable to the thickness of the vaporisation boundary layer in the drying problem, and that the strong variations in the liquid flux in this layer give rise to differently shaped impurity profiles to those previously predicted in the literature. Moreover, we investigate the evolution of the deposited impurity profile with depth, showing that the region of precipitation/deposition grows through the drying process at moderate deposition rates (relative to the drying rate), but that for higher deposition rates the deposition can remain confined to a fixed region near the surface.