Heat the oil in a large saucepan over medium-high head. Add the onions and cook, stirring often, until softened, about 3 minutes. Stir in the tomatoes and chicken stock. Reduce the heat to medium and cook, stirring often, until the sauce is reduced by about a third, 2 to 3 hours. Season with salt and pepper to taste.
Preheat the oven to 350°F. Spread a thin layer of tomato sauce in a large 9 x 13-inch baking pan. Sprinkle lightly with herbs.
Whisk together the ricotta, egg yolk, and nutmeg.
Place a layer of pasta in the pan. Spoon on some of the ricotta mixture and sprinkle with mozzarella and Parmesan. Layer with ham and spinach. Season with salt and pepper. Spoon on a bit of the sauce and sprinkle with herbs. Repeat layering. Top with a final sprinkling of mozzarella and Parmesan.
Bake for 45 to 60 minutes, until the cheese has melted. Cool slightly before cutting into squares.