Peru is racing to overhaul rules governing tens of thousands of informal miners before a year-end deadline that the government warns could otherwise push them into illegality overnight.