01 - Preheat 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 garlic and cook for 1 minute more. Remove from heat.
03 - In a small saucepan, heat cream, milk, thyme, nutmeg, black pepper, and remaining 1 tbsp butter over medium-low heat until steaming (do not boil). If using flour, whisk it in until smooth to slightly thicken.
04 - Layer 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 - Repeat with remaining potatoes, onions, and cheeses. Pour the warm cream mixture evenly over the layered ingredients.
06 - Cover tightly with foil and bake for 40 minutes until potatoes begin to soften.
07 - Remove foil and bake uncovered for an additional 20 minutes, or until the top is golden and the potatoes are fork-tender.
08 - Let rest 10 minutes before serving to allow layers to set. Garnish with fresh chives if desired.