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 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.
05 - Spread half of the caramelized onions over the potatoes. Sprinkle with half of the Gruyère and cheddar cheese.
06 - Repeat with remaining potatoes, onions, and cheeses.
07 - Pour the warm cream mixture evenly over the layered ingredients.
08 - Cover tightly with foil and bake for 40 minutes.
09 - Remove foil and bake uncovered for an additional 20 minutes, or until the top is golden and the potatoes are fork-tender.
10 - Let rest 10 minutes before serving. Garnish with fresh chives if desired.