01 - Preheat oven to 375°F. Grease a 9x13-inch baking dish thoroughly.
02 - Melt 2 tbsp butter in a large skillet over medium heat. Add sliced onions and a pinch of salt. Cook, stirring frequently, until deeply golden and caramelized, about 20-25 minutes. Add garlic and cook 1 minute more.
03 - Heat cream, milk, thyme, nutmeg, black pepper, and remaining 1 tbsp butter in a small saucepan over medium-low heat until steaming. If using flour, whisk in until smooth.
04 - Arrange half the sweet potato slices in the prepared dish. Season lightly with salt. Spread half the caramelized onions over potatoes. Sprinkle with half the Gruyère and cheddar.
05 - Repeat with remaining sweet potatoes, caramelized onions, and cheese blends.
06 - Pour warm cream mixture evenly over layered ingredients.
07 - Cover tightly with foil. Bake for 40 minutes.
08 - Remove foil. Bake uncovered for 20 minutes until top is golden and potatoes are fork-tender.
09 - Let gratin rest 10 minutes before serving. Garnish with fresh chives if desired.