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 during the final minute. Remove from heat.
03 - In a small saucepan, combine heavy cream, whole milk, dried thyme, ground nutmeg, black pepper, and remaining 1 tbsp butter. Heat over medium-low until steaming but not boiling. If thickening is desired, whisk in flour until smooth.
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, then sprinkle with half of the Gruyère and cheddar cheeses.
05 - Repeat with remaining sweet potatoes, caramelized onions, and cheese blend.
06 - Pour the warm cream mixture evenly over the layered ingredients, ensuring the liquid reaches all corners of the dish.
07 - Cover the dish tightly with aluminum foil. Bake for 40 minutes until potatoes begin to soften.
08 - Remove the foil and continue baking for an additional 20 minutes until the top is golden brown and bubbly, and potatoes are fork-tender when pierced.
09 - Let the gratin rest for 10 minutes before serving to allow the layers to set. Garnish with fresh chopped chives if desired.