Heat the oil in a large frying pan, and add the onion, garlic and mushrooms. Cook over a medium heat for 5 minutes, stirring regularly, until soft.
Meanwhile, add the walnuts to a food processor, and pulse a few times until the walnuts are coarsely ground.
Add the walnuts to the mushroom mixture, along with the remaining ingredients. Turn the heat up a little, and simmer gently for around 10 minutes, until the tomatoes have broken down and the mixture is at your desired consistency. Serve with spaghetti and grated cheese if desired.