Heat olive oil and butter in a large pan over medium heat.
Add onions and salt to the pan. Cook for 15 minutes, stirring occasionally, until the onions are caramelized. Add a splash of water as needed to prevent sticking.
Incorporate mushrooms into the pan and cook for about 7 minutes until they are soft.
Sprinkle flour over the onions and mushrooms, stirring to combine. Cook for a minute.
Pour in the white wine and let it cook for another minute until the wine slightly reduces.
Add the vegetable stock and fresh thyme to the pan. Stir well to combine and scrape the bottom of the pan to deglaze.
In a separate pot, cook the pasta in salted water until al dente. Reserve ½ cup of the pasta water before draining.
Add the drained pasta to the onion and mushroom mixture, stirring to combine. If the sauce is too thick, add a bit of the reserved pasta water to reach the desired consistency.
Remove the pan from the heat and sprinkle the shredded gruyere cheese over the pasta. Cover the pan with a lid for a minute to allow the cheese to melt.
Stir the melted cheese into the pasta and season with ground black pepper. Serve hot.