The evolutionary origins and consequences of self-fertility in nematodes