01 - Preheat your oven to 375°F. Grease a 9x13-inch baking dish with butter or cooking spray.
02 - In a large skillet over medium heat, melt 2 tbsp butter. Add sliced onions and a pinch of salt. Cook, stirring frequently, until onions are deeply golden and caramelized, about 20-25 minutes. Add minced garlic and cook for 1 minute more. Remove from heat.
03 - In a small saucepan, heat heavy cream, whole milk, dried thyme, ground nutmeg, black pepper, and remaining 1 tbsp butter over medium-low heat until steaming (do not boil). If using flour for thickening, whisk it in until smooth and slightly thickened.
04 - Arrange half of the sweet potato slices in the prepared baking dish. Season lightly with salt. Spread half of the caramelized onions over the potatoes. Sprinkle with half of the Gruyère and cheddar cheese.
05 - Create a second layer with remaining sweet potatoes, caramelized onions, and cheese blend. Ensure even distribution of ingredients.
06 - Pour the warm cream mixture evenly over the layered ingredients, ensuring the liquid penetrates through all layers.
07 - Cover the baking dish tightly with aluminum foil and bake for 40 minutes to allow potatoes to cook through.
08 - Remove foil and continue baking uncovered for an additional 20 minutes, or until the top is golden brown and bubbly, and potatoes are fork-tender.
09 - Let the gratin rest for 10 minutes before serving to allow the layers to set. Garnish with chopped fresh chives if desired.