Although my unique circumstances are different, I'd like to share that you are not alone in feeling trapped in one's job and city since I too have felt the exact same way in recent years.

I unfortunately can't offer very many solutions since I am in basically the same "trapped" situation currently (but towards the end here I can hopefully share a few things that keep me going).

For myself, the position I currently have in my hometown is the best I can hope for in this area, but the work/team environment have steadily become worse, particularly the last few years...being able to work from home last year helped out tremendously since it was something I had been hoping to have for some time, but the main kicker was simply being able to be around my kids more and have those smaller interactions with them on a more frequent basis and not deal with the office drama constantly.

Age-wise, we're the exact same, but education-wise you're further along than I'll likely ever get (I have some work towards a Masters in CS, but I'm poor at math, so with a completed PhD in CS in hand for yourself, I feel that opens up so many more doors than I could hope to receive). Housing-wise, I fortunately live in a somewhat rural area so housing prices aren't nearly as high as they are in other parts of California so we were able to take the plunge to purchase a home about two years ago (at times I feel that renting was definitely easier, but we were outgrowing our old place so I echo the sentiment of having one's own place to make "home" as being a positive).

I think the big thing I'm reading in your post above though is potentially that proximity to family and a city where you actually do feel like you're home and I can also echo that sentiment too. I spent a year in the Bay Area for school, but always felt that it was different than my home area, and later on during a short stint at a tech company in the Bay as well, those sorts of feelings returned too (it's difficult for me to say though whether I might have eventually felt "at home" if I had given myself more time but I'm not sure if that would have occurred or not).

In the last month my workplace has had myself return to the office and it created an immediate sense of sadness since I would no longer have the comfortable environment I had built up at home, nor would I get to see my children as often I had grown accustomed to. That I feel is the great drawback of so many companies pushing to bring their staff back onsite rather than adopting proper remote work options and allowing for it moving forward.

On top of that, I took a short (less than a week) vacation with the family, and had similar feelings as yours in my first day back in the office afterward since I just resented the thought of coming back into the office again so much after enjoying a few days away.

Also like you however, I've even shied away from wanting to apply for Software Engineering roles at other companies because I have the same concern regarding whether I would prefer the new work more than my existing work...or would it in fact be worse? That's the big concern (aside from the larger questions of whether remote work would be allowed and if I would be forced to make larger changes such as completely moving my family away to another city, etc. which also doesn't seem as appealing to have to put them/myself through either if it can be avoided).

So I wonder, what's my alternative to this line of work I've been in over the past decade+? And it's a really sobering thought since there would basically be nothing (that I can think of) that would come close in terms of salary so I feel forced to continue on in it (even though I do enjoy software development overall, I've also worked mostly independently since I'm basically a team of one, so I'm never sure if working in a larger software oriented organization might take away some of the enjoyment I've had working independently on software projects due to the extra rigor that might be needed on larger teams...overall though I'd still hope that the extra comradery would be a net plus on that scale).

Since you mentioned that your partner earns several multiples of your current salary I'm not sure what kind of accelerated timescale that might provide you as a couple to a potentially early retirement elsewhere (potentially closer to your hometown), but that might be consideration (although it doesn't help out with the here and now feelings which can't be worked around if you're still needing to go to work and experience those feelings daily).

For myself, it is difficult too...in years past what would sometimes help is me making attempts to get hired at tech companies (providing some small hope for that short period of time before being eventually rejected...which is also a not so great feeling so that's one reason why I've shied away from doing much of that lately), but at the moment I'm actually exploring Y Combinator's Cofounder matching area to see if that might provide me one path away from my current role I feel so stuck in and maybe take me into a new role (e.g. CTO) where I can provide more impact in a smaller company and get to stretch more of my brain and what I feel I can bring to an organization. I'm not sure if this experiment will pan out or not, but I'm hopeful for now :-).

Feel free to reach out via my email in my profile if you feel like sharing any more of the "struggle" we both seem to have (it's good to know I'm not alone in feeling that way either :-)!