Preheat the oven to 350 degrees F. Lightly oil a 9 x 13-inch baking pan. If using fresh spinach, chop it fine. If using frozen, chopped spinach, make sure it is thoroughly defrosted and squeeze out all of the excess water.
Place the ricotta or cottage cheese in a large bowl. Stir in the spinach, pesto, garlic, salt, pepper, half the Parmesan, and the walnuts. Mix well. Spread half the tomato sauce in the bottom of the pan. Place a layer of uncooked noodles over the sauce. Spoon about 1/3 of the ricotta or cottage filling in dabs over the noodles (you can spread it a little, but not too much) and sprinkle with 1/3 of the grated mozzarella. Follow with another layer of sauce, then noodles, followed by another 1/3 of the filling, and another 1/3 of the mozzarella. Repeat one more time, and then finish up with a final layer of noodles. You will have some Parmesan left over.
If you are using fresh noodles, bake uncovered. If you are using dried noodles, cover the pan tightly with foil.
Bake for 50 minutes, uncovering the pan (if applicable) during the last 15 minutes, during which time you can sprinkle on the reserved Parmesan. (In the case of the uncovered pan, if the top of the lasagna becomes as brown as you like it before the full baking time is up, cover loosely with foil and continue baking, so it wont get too dark.) Remove from the oven and let cool for about 10 minutes before serving.
Walnut Pesto: Place the basil leaves and garlic in a food processor or blender, and mix well.
Add the walnuts, and continue to blend until the walnuts are finely ground.
Keep the machine running as you drizzle in the olive oil. When you have a smooth paste, transfer to a bowl, and stir in the Parmesan. Season to taste with salt and pepper.
If you are not going to use the pesto right away, place in a container that has a tight-fitting lid. Smooth out the top surface of the pesto, and pour on enough olive oil to cover it completely. This creates an air-proof seal that helps preserve it well. Cover tightly and store in the refrigerator.