I'm not from such a country, but I do listen to The Weeds (a policy podcast) and they have discussed how it works. Roughly speaking, there are committees that look at the efficacy of new treatments and their costs, and they decide what they will pay for a given treatment. Then the drug maker decides if they will sell it at that price. There are cases where the government will not pay the drug maker's reserve price. For example, there was a period of time where Kadcyla was not available in the UK. Then, after a while, the drug maker decided to reduce their reserve price, and now it seems the Britons can get the drug.
This national pricing leverage is a big part of why drugs are cheaper in countries with national price setting. Socialized medicine is actually less of a factor in this space. What matters is whether a single entity has the ability to set prices for the entire market (or a sufficiently large slice of it).
https://pharmaphorum.com/news/kadcyla-set-regular-nhs-fundin...