If you look into it it is the COD that is electron donor and N2 that i the electron acceptor. While the energy (ATP) that is needed is derived from a redox reaction with COD as donor and O2 as acceptor.
N2 fixation will only happen when there is no soluble nitrogen available.