Why does magnesium form covalent bonds with carbon?
The crystal structure of calcium carbide gives a subtle hint of covalent bonding.  It looks like a rock salt structure, but note that the carbon atoms in the anions have their lone pairs directed towards the calcium atoms and so are favorably oriented for covalent overlap. The structure might be considered either a rock salt structure or a series of parallel $\ce{-Ca-C#C -}$ polymeric chains.



Source