For the crust: Preheat the oven to 375 degrees F. Pulse together the flour and salt in a food processor. Add the chilled butter and pulse just until the butter is evenly distributed throughout. Add the sour cream and continue to pulse 2 to 4 more times until just incorporated. Add 2 tablespoons of ice water at a time, pulsing after each addition, until the dough starts to hold together. Add more water as needed.
Turn the dough out onto plastic wrap and form it into a disc. Wrap the dough in the plastic wrap and let rest in the refrigerator 30 minutes.
Roll the dough on a floured surface into a 12-inch circle about 1/4-inch thick. Roll up the dough using a rolling pin, and gently lift and place it over a deep, 10-inch tart pan. Gently press the dough into all the crevices and trim the overhang to 1/2-inch. Crimp the edges for a decorative finish and use the trimmed dough to patch any holes.
Dock the bottom of the crust with a fork to keep it from puffing up, line with parchment paper and add dried beans to act as pie weights. Place on a large baking sheet and bake until the crust begins to brown, 20 to 30 minutes. Remove the parchment and dried beans.
For the custard: Melt the butter in a large saute pan over medium heat and saute the leeks until they soften and begin to caramelize, stirring occasionally, 8 to 10 minutes. Remove from the heat, cool and reserve.
Whisk the cream, milk, cornstarch, salt, pepper, cayenne, nutmeg and eggs in a large mixing bowl. Scatter the leeks evenly over the bottom of the crust. Top with the cheese and ham. Pour the custard over the top and place in the oven on a large sheet tray.
Bake until the center is set and the crust is golden brown, 40 to 45 minutes. Let cool on a wire rack. Serve warm or at room temperature.