Set the oven rack to the middle position and preheat to 400ºF.
Melt butter in a large skillet over medium-low heat. Add garlic and onions, saute until fragrant, 2 minutes.
Add flour, whisk to combine, stir and cook for 2 minutes.
Gradually whisk in milk and cook until thickened over medium heat, 2 to 3 minutes.
Turn off heat and whisk in salt, pepper, nutmeg, ½ cup gruyere, and ½ cup sharp cheddar cheese.
Grease the bottom and sides of an 8-inch square casserole dish.
Layer half of the potatoes, in overlapping rows in the dish. Spread half of the cheese sauce over the potatoes. Sprinkle ¼ cup gruyere and ¼ cup cheddar over the sauce.
Layer the remaining potatoes, followed by cheese sauce, and sprinkle with the remaining gruyere and cheddar cheese.
Cover with foil and place on a baking sheet. Bake for 30 minutes, remove the foil and bake until potatoes are tender and cheese is browned and bubbly, 20 to 25 minutes.