Electronic and structural properties of N and N2 in type-IV semiconductors