The disclosure provides compounds having formula (I), wherein the substituents are as defined herein. The compounds are useful for modulating the dopamine D3 receptor and for treating conditions associated therewith, such as addictions, drug dependency, and psychiatric conditions.