Structurally triggered metal-insulator transition in rare-earth nickelates