Is there any source for the custom to not buy things for a baby before it is born? I have heard that the reason is due to averting ayin hara, but I would like to know if there is any recorded source for this custom.
The first issue is the relationship of ayin hara to practical halacha.
This article explains in detail the Rambam's (Maimonides) objection to dealing with the "evil eye" as a real force when determining damages in halacha. Most other authorities of his time (i.e. rishonim) disagree, and do indeed treat ayin hara as a serious concern.
I have personally heard various contemporary authorities allow for the purchase of baby items before the birth.
Some rabbis feel that it is less of an ayin hara concern if:
The last point also explains why observant Jewish mothers typically do not have "baby showers".
In any case, there is no actual prohibition to buy baby items before the baby is born. One who takes the view of the Rambam need not even take the precautions listed above.