This is great timing, I'm just setting up a homelab and planning to run Immich on a mini PC server connected to a NAS. I did find icloudpd, which seems like a pretty reliable syncing tool for people in Apple ecosystem. https://github.com/icloud-photos-downloader/icloud_photos_do...
The Nextcloud app kind of does it, it seems. The fact that it stops working seems unrelated: starting the app doesn't make it recover, so it just seems buggy.
Nextcloud uses the location permission for some reason, presumably to wake up the app in the background once in a while? At least it can be closed (and "swiped away") for 2 months and keep syncing. Until it breaks and stops working entirely.