The Reproductive System (Mechasm in the Ace Books edition), a 1968 novel by John T. Sladek (rhymes with haddock).
The self-replicating machines are produced by the Wompler Toy Corporation:
Ignoring the frantic waving of the jar under his nose, Moley said, "Now, why don't we build a machine that can reproduce itself? I was reading about an idea like that in Life, just the other day. A self-reproducing machine—sure sounds easy enough, don't it?"
The machines are small gray boxes (depicted on this cover):
It was an array of gray metal boxes, each about the size of a cigarette package, stacked loosely together in a cube about two feet high. When the toggle switch, prominent on the top of any one box was thrown, it sent out a tuned starting signal to the rest; they were switched off in the same way.
As soon as each box was activated, it began to roll about on the table on its little casters, avoiding collision with its fellows When all the boxes were moving, they resembled a complicated Brownian movement on the dark surface of the table, as they explored every inch of it.
Kurt and Karl placed bits and scraps of metal on the table. The smaller bits were at once devoured by individual boxes, but the larger bars attracted the entire brood. The gray packages, now the size of king-size cigarette cases, swarmed over them like ants, gouging away with tiny cutters and torches—and growing fatter.
The machines get loose:
"Are you trying to tell me," asked Ickers, "that in only a few days these invisible bugs have piled up enough junk to cover twenty thousand square miles? And we can't stop this?"
"I'm afraid that is correct," said Smilax, "though rather pessimistic. They have worked underground for over two weeks, preparing for this takeover. Moreover, they have only fenced, or enclosed rather than covered the area, and I believe it to be only about 17,213 square miles. That you have had no success thus far in stopping it is evident," he added, with his eyes downcast. "That is why you have sent for me. I do foresee one way of stopping the Reproductive System—though you may find my way repugnant."
[. . . .]
Smilax lighted a display map. "The System seems to have three centers of growth, at the moment, and it is fencing off and surrounding the area between them. They are at the lab at Millford, Utah; Altoona, Nevada; and Las Vegas. The judicious detonation of three thermonuclear devices of the order of 150 megatons each would, I feel confident, completely neutralize the System at these points. The remainder would be a simple matter of—I believe the expression is 'mopping up'—using smaller thermonuclear devices. I know what question you are going to raise in advance, so let me say I estimate the total number of civilian casualties at no more than a million."