Mix the flour and the salt in a bowl and add the butter. Work the butter and the flour together using a pastry blender (or your hands) until the mixture is generally uniform but with some of the butter in large, irregular chunks. Stir mixture with a fork and add 2 tablespoons water. Mix until dough begins to clump. Add more water if necessary. Roll the mixture into a ball, then press into a large disc. Wrap dough in plastic wrap, place in the refrigerator and let it rest for an hour.
Once rested, place the dough on a lightly floured surface and dust the top of dough with flour. Using a rolling pin, roll the dough out evenly into a 12-inch round, about an eighth-inch thick. Line a 9-inch pie pan with the dough and fold the extra into the edges to make a thicker ridge around the border. Use a fork or a skewer to prick the bottom of the dough. Place back in the refrigerator and let rest for another hour.
Preheat oven to 375°. Line the pie crust with foil or parchment paper and fill the pie with a layer of dried beans. Bake for 15 minutes, until the shell is beginning to brown along the edges. Remove the parchment paper and the beans and return the shell to the oven. Bake for another 5 minutes, until the crust is an even golden brown. Remove from oven and let cool.
Heat a heavy-bottomed skillet over medium heat and add the butter. When butter is melted, add the onions and thyme and cook for 15 to 20 minutes, until soft, golden and fragrant. Remove from the pan and let cool. Season with salt and pepper to taste.
Cut the bacon into small pieces and cook until barely crispy. Set aside.
In a large bowl, whisk the half and half, eggs, egg yolks and cheese together. Season with salt, pepper and a pinch of cayenne pepper.
Spread the bacon in the baked pie crust, followed by the onions. Add the egg mixture and bake for about 40 minutes. The pie should look puffed up and golden brown. Let stand for 10 minutes before cutting.