The evolutionary link between nitrogen fixation and bacterial photosynthesis