The safest drug with the least negative effect on sleep quality that also has a very good safety profile (compared to other sleep drugs) is eszopiclone (Lunesta in the US).
When they were introduced, the "z-drugs" -- zolpidem (Ambien), eszopiclone (Lunesta), and zaleplon (Sonata, all US names) were recommended for a few days to weeks at max. A recent trial had patients taking up to 3 mg of eszopiclone for as long as six months. Tolerance is less of an issue than with benzos and other hypnotics (the z-drugs), there are fewer side effects, it is more effective than things like the atypical or cyclic antidepressants, and doesn't just royally fuck your sleep architecture. None of the other highly effective sleep drugs has been trialed for that long without things going really sideways.
One will almost certainly become dependent after this period, but discontinuation can be done gradually by stepping down to the 2 mg tablet, then 1 mg, then 0.5 mg. A month is a reasonable time to expect the weaning process to make the transition off to be as smooth as possible.
If you haven't tried it, it's available through a few vendors here and, since there's literature on it, an informed physician (especially a psychiatrist) will be open to it. Hell, most of them have no problem writing scripts for Ambien year after year for people. Give it a try and see if it works.
One really effective but potentially dicey option is quetiapine, an anti-psychotic that can also treat depression and certainly has a sedative effect. The cautionary note: this will make you so hungry, you'll fuck a hobo for a ham sandwich. If you are careful, and titrate up slowly, you can find a dose that helps you meet the caloric needs for a bulk and really knocks you out. It has a pronounced hangover effect in many people, but like the hunger effect, it has a dose-response curve. So if you attempt this route because you're trying to put on weight and also improve your sleep, again, go slowly. Even after you stop the drug and the serum level of hunger hormones (leptin, ghrelin, and peptide YY) return to normal, their concentrations in cerebrospinal fluid can remain altered for months to years.
I gained 60 lbs in two months accidentally, eating so ravenously that I would vomit, return to sleep, and then wake up and finish the second pizza of the two-pizza combo that I ordered. It is not to be fucked with.