In a large skillet or heavy-bottomed pot, melt the butter over medium heat.
Add the sliced onions and cook, stirring occasionally, for 15–20 minutes until softened and golden brown.
Stir in the garlic, sugar, and salt, cooking for an additional 2–3 minutes until fragrant.
Pour in the white wine to deglaze the pan, scraping up any browned bits from the bottom.
Simmer for 3–5 minutes until the wine reduces slightly.
Add the beef broth, thyme, and bay leaf to the onions.
Bring to a gentle boil, then reduce the heat and simmer uncovered for 10–15 minutes to allow the flavors to meld.
While the sauce simmers, cook the pasta in salted boiling water according to package instructions until al dente.
Drain the pasta, reserving ½ cup of pasta water.
Remove the bay leaf from the sauce.
Toss the cooked pasta into the onion sauce, stirring to coat. Add a splash of reserved pasta water if the sauce is too thick.
Stir in half of the shredded Gruyère cheese, letting it melt into the sauce.
Transfer the mixture to a greased baking dish. Top with the remaining Gruyère cheese.
Preheat your oven to 375°F (190°C).
Bake the dish for 10–15 minutes, or until the cheese is bubbly and golden.
Remove from the oven and let it cool slightly.
Garnish with chopped parsley, and season with additional salt and pepper to taste.
