Preheat oven to 350 degrees F. Grease two 9-inch pans, line with parchment, grease parchment.
Whisk together flour, baking soda, baking powder, all spices, and salt in a large bowl.
In a separate bowl, whisk both sugars with oil until combined. Add eggs one at a time. Add vanilla.
Add dry ingredients to wet and mix with a spatula until just combined.
Fold in finely grated carrots, drained pineapple, and nuts if using.
Divide batter between prepared pans. Bake 30 to 35 minutes until a toothpick comes out clean.
Cool in pans 15 minutes, then turn onto a wire rack to cool completely before frosting.
For frosting: beat cream cheese and butter until completely smooth, 2 to 3 minutes.
Add powdered sugar one cup at a time on low speed. Add vanilla, salt, and sour cream.
Beat on medium for 1 minute until thick and smooth. Refrigerate 20 minutes if too soft.
Level layers if needed. Assemble with frosting between layers.
Apply a thin crumb coat, refrigerate 20 minutes, then apply final frosting layer.