Melt the butter in a large non-stick sauté pan. Add the onion and the potatoes. Start with the heat at medium-low. When all the vegetables are soft begin raising the heat. Continually turn the vegetables over and over to evaporate the liquid. Continue until nearly all the liquid has been evaporated. Set the vegetables aside.
Next, make the béchamel sauce: whisk the flour and milk together in a sauce pan. Make sure all the flour has been combined with the milk. Cook over medium-high heat while whisking. Cook until the mixture is thick. Beat the eggs, one at a time, into the mixture. Add finely grated cheese if using.
Season the béchamel well with salt and pepper and fresh grated nutmeg.
To assemble: Season the potatoes with salt and pepper. Combine the vegetables and the béchamel sauce. Pour into a buttered gratin dish and bake for about 30 minutes in a 350 degree oven. Make sure the center of the gratin is completely cooked. This dish can be assembled the day before and refrigerated. Bring it from the refrigerator an hour before baking. Increase the baking time an additional 5-10 minutes. Top with toasted, crushed walnuts or hazelnuts.
You can also bake this gratin in ramekins. Butter 6-8 small ramekins. Cut circles of parchment paper to place in the bottom of each ramekin. Butter the parchment. Fill the ramekins with the potato mixture. Bake for about 20 minutes. Run a knife around the edge of the ramekin and then turn the timbales out on to a plate. Remove the parchment paper.