Heat oven to 180C/160C fan/gas 4 and grease a shallow ovenproof dish about 35 x 24cm. Melt the butter in a non-stick frying pan, add the onions and fry for 10 mins, stirring frequently, until soft and starting to turn golden. Sprinkle over some seasoning and the sugar, stir again, then cook 5-10 mins more until golden. Meanwhile, heat the milk with the nutmeg, garlic, thyme and seasoning. When the mixture starts to boil, pour in the cream and turn off the heat.
Quarter the celeriac and thinly slice, then arrange in the base of the dish. Pour over half the milk mixture, then spoon over the golden onions. Thinly slice the ends of the potatoes, reserving the middles. Pile the sliced potatoes into the dish, then thinly slice the reserved middle sections and arrange neatly on top. (By cutting the potatoes this way, you should have neat slices roughly all the same size for the top of the gratin.) Pour over the remaining milk mixture, scatter over the Parmesan and bake for 1 hr 30 mins until a knife easily cuts through the layers. Allow to rest for 10 mins before serving to allow the creamy sauce to soak into the potatoes.