Bring a large pot of salted water to a boil.
Meanwhile, in a large skillet, heat the butter over medium heat. Add the onions and garlic and cook over medium heat until soft and translucent, about twenty minutes, stirring occasionally.
Add the thyme to the skillet, season with salt and black pepper, and cook for two minutes, until fragrant.
Add the pasta to the pot of boiling water and cook until al dente, or two minutes less than the package instructions. Reserve a cup of the pasta water. Drain the pasta and set aside.
Meanwhile, sprinkle the flour over the onions and stir to combine.
Pour in the white wine while stirring constantly, to avoid any lumps. Then pour in the beef broth and continue to cook, stirring constantly, until the mixture thickens, about 10 minutes.
Combine the cooked pasta with the onion sauce and toss until the pasta is evenly coated.
Over low heat, stir in the grated gruyère cheese until melted and fully combined. Add 1/4 cup of the reserved pasta water to help thicken the sauce and help it bind to the pasta. Add more if needed.
Serve hot, garnished with fresh parsley if desired.