In a large skillet, melt the butter over medium heat. Add the onion and cook until browned, 20 to 25 minutes.
Bring a large pot of water to a boil, salt it, add the pasta and cook until al dente. Drain, reserving 1 cup pasta cooking water.
While the pasta is working, in a small saucepan, heat the EVOO, garlic and rosemary sprig over medium-low heat and let steep for 5 minutes. Let cool for a few minutes, then discard the rosemary and pour the oil and garlic into a food processor. Add the nuts and spinach and process into a thick paste. Season with salt, pepper and the nutmeg, if using.
Stir the pasta cooking water into the caramelized onions, then stir in the pesto. Add the pasta and cheese and toss to combine.