The Hadamard formula for nonlocal eigenvalue problems