Photograph: Brett Stevens
Melt the butter in a large pan and cook the onions with 1 teaspoon of salt for 30 minutes, uncovered, stirring often, until caramelised.
Add the garlic and thyme, then the white wine, and simmer until the wine has evaporated. Add the stock to the pan and simmer the soup, uncovered, for 30 minutes.
Towards the end of the simmering time, preheat the grill to high. Lay the slices of bread on a baking sheet and grill on one side only until toasted. Remove from the grill, turn over and sprinkle the untoasted sides with grated Gruyère.
Check the soup's seasoning and adjust if necessary, then pour into heatproof bowls. Top each serving with a slice of cheese-topped baguette and scatter over a few small thyme sprigs.
Place the bowls under the grill until the cheese on the bread is bubbling and golden brown.