Melt the butter in a saucepan over medium heat, add the onion and cook until tender, about 3-5 minutes.
Add the garlic and thyme and cook until fragrant, about a minute.
Sprinkle in the flour, mix well and cook until it starts to turn lightly golden brown, about a minute.
Add the milk and cook until the sauce thickens, about 1-2 minutes.
Reduce the heat, add 1/2 cup of the cheese, mix and let it melt into the sauce before adding the nutmeg and seasoning with salt and pepper to taste.
Spread some of the sauce over the bottom of a large baking dish (or casserole dish or cast iron pan) and place the potatoes in with sauce between each layer. (I like to dip each slice into the sauce as I place them into the pan.)
Pour any remaining sauce over the potatoes in the pan, sprinkle on the remaining cheese.
Bake in a preheated 350F/180C oven until the potatoes are tender, about 45-60 minutes.