We study the thermodynamics of boron (B) incorporation into gallium nitride (GaN) using first-principles calculations. In the dilute limit, we have calculated the formation energies of different configurations of the B impurity in GaN and found that substitution on the cation site is favored over substitution on the anion site. Under $p$-type conditions, interstitial boron can become the more favorable configuration and will ultimately limit the $p$-type conductivity. At higher B concentrations we use the generalized quasi-chemical approximation to elucidate the thermodynamic stability of boron gallium nitride (BGaN) alloys. We also investigate the effects of strain, which will be present if BGaN alloys are grown pseudomorphically on a GaN substrate. Without strain, B incorporation at typical growth conditions is limited to about 1.4% at $800{\phantom{\rule{0.16em}{0ex}}}^{\ensuremath{\circ}}\mathrm{C}$. Pseudomorphic strain raises the limit to 3.0% at the same temperature, close to experimentally observed levels of B incorporation.