c. 2400 BCE, in the Pyramid Texts
Creation at Heliopolis
One god alone on a mound in the water, producing the first pair from himself.
Before anything there is Nun: a dark, limitless, motionless water. It is not nothing. Egyptian thought had no concept of creation from nothing, and Nun never goes away; it remains outside and underneath the ordered world for as long as the world lasts.
Out of it a mound rises, and on the mound Atum comes into being by himself. Alone, with no partner, he produces the first pair: Shu, air, and Tefnut, moisture. The texts are direct about the mechanism, giving it as masturbation in some versions and as spitting or sneezing in others, and they are not embarrassed by it.
Shu and Tefnut produce Geb, the earth, and Nut, the sky, who are locked together until Shu forces them apart and holds them apart, which is what makes a space for anything to happen in. Geb and Nut then produce Osiris, Isis, Set and Nephthys. Those nine are the Ennead.
Where it comes from
The Pyramid Texts
About this sourcec. 2400 BCE. The oldest substantial religious writing to survive from anywhere, and the Ennead is already assumed in it.
The Coffin Texts
About this sourcec. 2100 BCE onward. Adds material, including Atum's own account of what he did.
What the story was for
A genealogy and a cosmology in the same structure, which is why it won. Making the earth male and the sky female is an inversion of most neighbouring traditions and is deliberate. Making the void between them a person, who has to hold the two apart by continuous effort, tells you that Egyptians regarded order as something maintained rather than something settled: the world is being held open, and it could close.
Other myths