  The presence of cold ($T \lesssim 10^4$ K) gas in the circumgalactic medium
(CGM) of galaxies has been confirmed both in observations and high-resolution
simulations, but its origin still represents a puzzle. Possible mechanisms are
cold accretion from the intergalactic medium (IGM), clumps embedded in outflows
and transported from the disk, gas detaching from the hot CGM phase via thermal
instabilities. In this work, we aim at characterizing the history of cold CGM
gas, in order to identify the dominant origin channels at different
evolutionary stages of the main galaxy. To this goal, we track gas particles in
different snapshots of the SPH cosmological zoom-in simulation Eris2k. We
perform a backward tracking of cold gas, starting from different redshifts,
until we identify one of the followings origins for the particle: cold inflow,
ejected from the disk, cooling down in-situ or stripped from a satellite. We
also perform a forward tracking of gas in different components of the galaxy
(such as the disk and outflows). We find a clear transition between two epochs.
For $z>2$, most cold gas (up to 80%) in the CGM comes from cold accretion
streams as the galaxy is accreting in the "cold mode" from the IGM. At lower
$z$, gas either cools down in-situ after several recycles (with 10-20% of the
gas cooling in outflow), or it is ejected directly from the disk (up to 30%).
Outflows have a major contribution to the cold CGM gas budget at $z<1$, with
almost 50% of hot gas cooling in outflow. Finally, we discuss possible
mechanisms for CGM cooling, showing that the thermally unstable gas with
$t_{\rm cool}/t_{\rm ff}<1$ (precipitation-regulated feedback) is abundant up
to $r\sim 100$ kpc and cooling times are shorter than 50 Myr for densities
$n>10^{-2}\,{\rm cm}^{-3}$.
