Begin by melting the butter in a saucepan over medium heat. Add in the chopped onion and sauté until soft, about 3-5 minutes.
Stir in the minced garlic and thyme, cooking for another minute until fragrant.
Sprinkle the flour over the mixture, stirring well, and cook until it starts to lightly brown, which should take about a minute.
Gradually pour in the milk, stirring continuously until the sauce thickens—this usually takes 1-2 minutes.
Lower the heat, add in 1/2 cup of the Gruyere cheese and let it melt into the sauce. Then, season with nutmeg, salt, and pepper as per taste.
Layer some of this creamy sauce at the bottom of a large baking dish, then arrange the thinly sliced potatoes in the dish, placing sauce between layers.
Once all the potatoes are in, pour the remaining sauce over them and top it off with the rest of the cheese.
Bake in a preheated oven at 350°F for about 45-60 minutes until the potatoes are tender and the top is golden brown.