Peel and grate the carrots using the large holes of a box grater or a food processor grating attachment. Set a large, heavy-bottomed pot or deep skillet over medium heat.
Add the grated carrots and milk. Bring the mixture to a gentle simmer, stirring often to prevent the milk from catching on the bottom of the pot.
Cook until the carrots are very tender and most of the milk has cooked down, about 30 to 35 minutes. Stir more frequently as the mixture thickens.
Stir in the sugar, 2 tablespoons of the ghee, cardamom, and salt. Continue cooking and stirring until the halwa is thick, glossy, and pulls together in the pot, about 8 to 10 minutes.
Meanwhile, heat the remaining 1 tablespoon ghee in a small skillet over medium-low heat. Add the pistachios or almonds and the optional raisins. Cook just until fragrant and lightly toasted, about 1 to 2 minutes.
Spoon the gajar halwa into a serving dish. Scatter the toasted nuts and raisins over the top. Serve warm, at room temperature, or chilled.