01 - Preheat oven to 350°F (180°C). Generously butter a 2-quart baking dish.
02 - In a saucepan, combine heavy cream, whole milk, garlic, thyme, nutmeg, salt, and black pepper. Warm gently over low heat until steaming but not boiling. Remove from heat and set aside.
03 - Arrange half the sweet potato slices in an even layer in the prepared dish. Layer with half the sliced onions and one third of the Gruyère cheese. Repeat with remaining sweet potatoes and onions.
04 - Pour the warm cream mixture evenly over the layered vegetables. Scatter the remaining Gruyère on top and dot with pieces of butter.
05 - Cover the dish tightly with foil and bake for 35 minutes. Remove foil and continue baking for 15 to 20 minutes, or until the potatoes are tender and the top is golden and bubbling.
06 - While the gratin bakes, line a baking tray with parchment paper. In a small saucepan over medium heat, combine granulated sugar and water; stir until dissolved. Cook, undisturbed, until the syrup turns a deep amber, about 3 to 4 minutes. Immediately stir in toasted hazelnuts and a pinch of salt, then transfer onto the prepared tray. Let cool completely and chop coarsely.
07 - Just before serving, sprinkle the caramelized hazelnuts over the gratin for a crunchy finish.