First-principles calculations of niobium hydride formation in superconducting radio-frequency cavities