Preheat the oven to 200C/180C fan/Gas 6. Place the sausages on a baking tray and cook for 20-25 minutes, turning halfway, until golden and cooked through.
Meanwhile, boil the potatoes in salted water for 15-20 minutes until very tender. Drain well.
Mash the potatoes with the butter and milk until smooth. Season well and keep warm.
While the potatoes boil, heat the oil in a frying pan. Add the sliced onions and cook over medium-low heat for 15 minutes, stirring occasionally, until deeply golden and caramelised.
Sprinkle the flour and thyme over the onions. Stir and cook for 1 minute.
Gradually pour in the stock, stirring constantly. Simmer for 3-4 minutes until you have a thick gravy. Season with salt and pepper.
Serve the sausages on top of the mash with the onion gravy poured over everything.