On the formation of CO2 and other interstellar ices