Preheat the oven to 180 °C. Peel off the outer skin of the garlic bulbs, cut the bulbs diagonally so that the cloves are exposed. Brush the bulbs and the cuts with olive oil, place in an ovenproof dish and roast in the oven until soft (approx.
1 hour). Chop half of the walnuts and spread the rest evenly on an ungreased baking sheet. Remove the soft roasted garlic bulb from the stove and cool a bit.
In the meantime, put the baking sheet with the walnuts in the stove and roast for 5 min. Take them out and let them cool down.
Bring a saucepan of pasta water to a boil. As soon as you can touch the garlic bulbs, squeeze the pulp from the cloves and put them in a frying pan with 4 tablespoons of olive oil and the finely chopped walnuts. Heat and saute for 5 minutes at a moderate temperature until soft. Mix in the chopped parsley, season with salt and season with pepper. In the meantime, cook the pasta in enough salted water until just al dente.
Skim off a ladle of pasta water and set aside. Drain spaghetti and toss briefly in skillet until evenly coated with garlic sauce. Stir with a little pasta water as needed until smooth. Divide the spaghetti evenly among plates, sprinkle with the toasted walnuts and bring to the table.