Add the flour and salt to a mixing bowl. Add the cold cubed butter and work it into the flour using your fingertips until the mixture resembles coarse breadcrumbs with a few pea-sized butter pieces.
Gradually add the ice-cold water, one tablespoon at a time, until the dough starts coming together. Avoid overworking it. Shape the dough into a flat disc, wrap it, and refrigerate for at least 30 minutes.
Heat the butter and olive oil in a large skillet over medium-low heat. Add the thinly sliced onions and salt, stirring until they are evenly coated.
Cook slowly for 30–35 minutes, stirring occasionally, until the onions become soft, golden brown, and naturally sweet. Lower the heat if they start browning too quickly.
Add the black pepper, fresh thyme, optional sugar, and balsamic vinegar. Stir well and cook for another 2 minutes. Remove from the heat and let the onions cool slightly.
Lightly flour your work surface and roll the chilled dough into a circle large enough to fit a 9-inch tart pan. Carefully transfer it to the pan, pressing gently into the bottom and sides.
Trim any excess dough and prick the base lightly with a fork. Refrigerate for another 10 minutes to help the pastry hold its shape. Line the pastry with parchment paper and fill it with baking weights or dried beans.
Bake for 15 minutes. Carefully remove the parchment paper and weights, then bake for another 5 minutes until the base looks lightly golden. Allow it to cool slightly.
In a mixing bowl, whisk together the eggs and heavy cream until smooth. Add the shredded Gruyère, Parmesan, nutmeg, and a little freshly ground black pepper.
Mix until everything is evenly combined. Assemble the Tart. Spread the caramelized onions evenly over the partially baked tart crust.
Pour the creamy egg mixture over the onions, making sure the filling is distributed throughout the tart. Gently spread the cheese mixture if needed.
Place the tart in the preheated oven and bake for 25–30 minutes, or until the filling is set and the top develops a beautiful golden color.
Remove the tart from the oven and let it rest for 10–15 minutes before slicing. This helps the filling settle and makes serving easier.