Prep the oven and dish: Heat the oven to 375°F (190°C). Grease a 2-quart baking dish with butter or olive oil.
Slice the potatoes: Peel and slice potatoes about 1/8 inch thick.
A mandoline helps keep slices even. Rinse quickly and pat dry to remove excess starch.
Start the sauce: In a medium saucepan, melt butter over medium heat. Add minced onion and cook until soft and translucent, 3–5 minutes.
Stir in garlic and thyme; cook 30 seconds until fragrant.
Add cream and seasonings: Pour in the cream (and milk if using). Add nutmeg, 1 teaspoon salt, and 1/2 teaspoon pepper. Warm gently until steaming, not boiling.
Taste and adjust seasoning.
Layer the potatoes: Spread a thin layer of cream mixture on the bottom of the baking dish. Arrange a snug layer of potatoes. Spoon over more cream to lightly coat, then sprinkle with some Gruyere and a little Parmesan.
Repeat layers: Continue layering potatoes, cream, and cheeses until you’ve used everything.
Finish with a generous layer of Gruyere and a dusting of Parmesan on top.
Cover and bake: Cover the dish loosely with foil (tent so it doesn’t touch the cheese). Bake for 35–40 minutes, until the potatoes are mostly tender when pierced.
Uncover and brown: Remove foil and bake another 15–20 minutes, until bubbling and golden on top. If you want extra color, broil for 1–2 minutes, watching closely.
Rest and serve: Let the dish rest 10–15 minutes before serving.
This helps the sauce set so slices hold together.