Melt the butter in a heavy-based saucepan and add the onion. Cook over low heat, stirring occasionally, for 25 minutes, or until the onion is deep golden brown and beginning to caramelise.
Add the garlic and flour and stir continuously for 2 minutes. Gradually blend in the stock and wine, stirring all the time, and bring to a boil. Add the bay leaf and thyme and season.
Cover pan and simmer for 25 minutes. Remove the bay leaf and thyme and check the seasoning. Preheat the grill.
Toast the baguette slices, the divide among six warmed soup bowls and ladle the soup over the top. Sprinkle with grated cheese and grill until cheese melts and turns light golden brown.