A compound of formula or a pharmaceutically acceptable salt thereof, wherein n is 0, 1, 2, 3, or 4; p is 0, 1, 2, 3, 4, or 5; A is a five- or six-membered partially or fully unsaturated ring optionally containing one, two, three, or four heteroatoms selected from nitrogen, oxygen, and sulfur; D is a five- to eight-membered partially or fully unsaturated ring optionally containing one, two, three, or four heteroatoms selected from nitrogen, oxygen, and sulfur; wherein the five- to eight-membered ring is optionally fused to a second five- to eight-membered partially or fully unsaturated ring optionally containing one, two, three, or four heteroatoms selected from nitrogen, oxygen, and sulfur; R 2 is selected from hydrogen, alkenyl, alkyl, and cycloalkyl, wherein the alkenyl, alkyl, and cycloalkyl are optionally substituted with halo; R 3 is alkyl; R 4 is heterocyclyl; each R 5 is independently selected from alkoxy, alkoxycarbonyl, alkyl, alkylcarbonyl, alkylsulfahyl, aryl, carboxy, cyano, cycloalkyl, cycloalkyloxy, halo, haloalkyl, haloalkoxy, heterocyclyl, hydroxy, -NR c R d, (NR e R f)carbonyl, (NR e R f)sulfonyl, and oxo; provided that when A is a six-membered substituted ring all R 5 groups on the ring other than those where R 5 is fluoro must be in the meta and/or para positions relative to the ring's point of attachment to the parent molecular moiety; each R 6 is independently selected from alkoxy, alkoxycarbonyl, alkyl, alkylcarbonyl, alkylsulfanyl, alkylsulfonyl, aryl, aryloxy, carboxy, cyano, cycloalkyl, cycloalkyloxy, halo, haloalkoxy, haloalkyl, heterocyclyl, hydroxy, -NR c R d, (NR e R f)carbonyl, (NR e R f)sulfonyl, and oxo; R 7 is cycloalkyl; R c and R d are independently selected from hydrogen, alkoxyalkyl, alkoxycarbonyl, alkyl, alkylcarbonyl, arylalkyl, haloalkoxyalkyl, haloalkoxycarbonyl, haloalkyl, and (NR e R f)carbonyl; and R e and R f are independently selected from hydrogen, alkyl, aryl, arylalkyl, and heterocyclyl; wherein the aryl, the aryl part of the arylalkyl, and the heterocyclyl are optionally substituted with one or two substituents independently selected from alkoxy, alkyl, and halo. n is 0, 1, 2, 3, or 4; p is 0, 1, 2, 3, 4, or 5; A is a five- or six-membered partially or fully unsaturated ring optionally containing one, two, three, or four heteroatoms selected from nitrogen, oxygen, and sulfur; D is a five- to eight-membered partially or fully unsaturated ring optionally containing one, two, three, or four heteroatoms selected from nitrogen, oxygen, and sulfur; wherein the five- to eight-membered ring is optionally fused to a second five- to eight-membered partially or fully unsaturated ring optionally containing one, two, three, or four heteroatoms selected from nitrogen, oxygen, and sulfur; R 2 is selected from hydrogen, alkenyl, alkyl, and cycloalkyl, wherein the alkenyl, alkyl, and cycloalkyl are optionally substituted with halo; R 3 is alkyl; R 4 is heterocyclyl; each R 5 is independently selected from alkoxy, alkoxycarbonyl, alkyl, alkylcarbonyl, alkylsulfahyl, aryl, carboxy, cyano, cycloalkyl, cycloalkyloxy, halo, haloalkyl, haloalkoxy, heterocyclyl, hydroxy, -NR c R d, (NR e R f)carbonyl, (NR e R f)sulfonyl, and oxo; provided that when A is a six-membered substituted ring all R 5 groups on the ring other than those where R 5 is fluoro must be in the meta and/or para positions relative to the ring's point of attachment to the parent molecular moiety; each R 6 is independently selected from alkoxy, alkoxycarbonyl, alkyl, alkylcarbonyl, alkylsulfanyl, alkylsulfonyl, aryl, aryloxy, carboxy, cyano, cycloalkyl, cycloalkyloxy, halo, haloalkoxy, haloalkyl, heterocyclyl, hydroxy, -NR c R d, (NR e R f)carbonyl, (NR e R f)sulfonyl, and oxo; R 7 is cycloalkyl; R c and R d are independently selected from hydrogen, alkoxyalkyl, alkoxycarbonyl, alkyl, alkylcarbonyl, arylalkyl, haloalkoxyalkyl, haloalkoxycarbonyl, haloalkyl, and (NR e R f)carbonyl; and R e and R f are independently selected from hydrogen, alkyl, aryl, arylalkyl, and heterocyclyl; wherein the aryl, the aryl part of the arylalkyl, and the heterocyclyl are optionally substituted with one or two substituents independently selected from alkoxy, alkyl, and halo.