Caramelize the onions: Heat butter and olive oil over medium-low heat. Add onions and cook for 25–35 minutes, stirring occasionally, until deeply golden and sweet. Add garlic during the final minute.
Make the sauce: Warm the cream and milk in a saucepan. Stir in thyme, salt, pepper, and nutmeg. Remove from heat and mix in about ½ cup Gruyère.
Layer: Grease a baking dish. Arrange a layer of potatoes, followed by caramelized onions and a little Gruyère. Repeat until everything is used.
Add the cream: Pour the warm cream mixture evenly over the potatoes.
Top with cheese: Sprinkle the remaining Gruyère generously over the top.
Bake: Cover with foil and bake at 190°C / 375°F for 45 minutes. Remove the foil and bake another 25–35 minutes, until bubbling, golden, and the potatoes are fork-tender.
Rest: Let stand for 10–15 minutes before serving so the creamy layers can set.