Nucleosynthesis constraints on scalar-tensor theories of gravity