Preheat the oven to 375°F (190°C).
Generously butter a 9×13-inch baking dish.
In a large pot, melt 6 tablespoons of butter over medium heat.
Whisk in the flour and cook briefly to form a roux.
Gradually whisk in the whole milk, ensuring the mixture is smooth.
Add salt, pepper, and nutmeg, and heat until slightly thickened.
Stir in about 1 1/2 cups of the shredded cheese until melted and incorporated.
Arrange a layer of sliced potatoes evenly in the prepared dish, then add some sliced onions.
Pour a portion of the creamy sauce over the potatoes and onions.
Repeat layering with potatoes, onions, and sauce until all ingredients are used.
Sprinkle the remaining shredded cheese over the top, then finish with the grated Parmesan.
Cover the dish with foil and bake for about 45 minutes.
Remove the foil and bake an additional 20–30 minutes until the potatoes are tender and the top is golden and bubbling.
Let the dish rest for about 10 minutes before serving so the sauce