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 items could be returned
the items could be used as a baby gift for someone else
the acquisition of items is not done in a public, celebratory way
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.