Open charm tomography of cold and hot nuclear matter