2nd probably has a lot of it, although people obviously do form opinions radically different from their birth environments also, so parents aren't the whole story.
I'd guess that there are a wide variety of mechanisms. SOme comes from peer groups or parents. Others find philosophies that comport with their self image (e.g., someone who gets a job in Wall Street suddenly becomes an economic conservative). For some, it might start with a philosophical/ethical approach to the world in general and then the application of that to the political realm flow from that. In some cases, a combination of factors.
For my part, the overwhelming influence was having been raised and taken to Christianity early on (I am no longer Christian) which led to a strong concern for the weak, compassion, and for non-violence in our interactions with others. That gave rise to a very staunch liberal (in the American sense) philosophy. I was also a scientist and have a strong orientation toward evidence based thinking, which also made me turn strongly to environmentalism, left me very skeptical of conservative economics, and sharply against the US Republican party. Finally, my peers from my time in Germany as a high school student also reinforced my social democratic tendencies.