livesync obsidian notes with your nas
Hello friends, been a while.
Today I changed the themes on my VS Code and Obsidian to light mode. Using the Primary theme. It’s something new… I haven’t tried anything light mode for like a decade, it’s time to give it a shot.
Anyway, I also moved away from syncing my notes with google drive finally, and to a self-hosted solution (mostly) using my Ugreen NAS, tailscale as my VPN, and the Self-Hosted LiveSync community plugin for Obsidian. This was mostly for getting my apple phone to be able to sync to these notes as well. But this has the added bonus of allowing my linux machines to livesync, instead of relying on git, and not to mention helps me ever-so-slightly escape the tight grasp of big tech.
Livesync for Obsidian (to work with Linux / IOS)
I went through a bit of an ordeal getting livesync to work across my phone, and devices.
Prerequisites / Technologies used:
- Obsidian (obviously)
- Tailscale
- UGreen NAS -> with docker
UGreen Setup:
After we make sure Docker is installed
CouchDB using Docker
- Within docker shared folder, created couchdb directory and data and config subdirectories
- Within docker application, found couchdb official image, instantiated container with Auto-Restart, Network mode Bridge, binded the physical folder
/docker/couchdb/datato/opt/couchdb/data; and the same to/opt/couchdb/etc/local.dto/docker/couchdb/config. Added two environment variables for an admin user:COUCHDB_USERandCOUCHDB_PASSWORD. REMEMBER the NAS-side port / Host Port for the container’s5984port for use later - After container created, open bin/bash terminal from the running container within the app. Run the following commands:
# Create the _users database
curl -X PUT http://your_username:your_strong_password@<YOUR-NAS-IP>:5984/_users
# Create the _replicator database
curl -X PUT http://your_username:your_strong_password@<YOUR-NAS-IP>:5984/_replicator
# Create the _global_changes database
curl -X PUT http://your_username:your_strong_password@<YOUR-NAS-IP>:5984/_global_changes
# Create obsidian vault -- this name will be important later
curl -X PUT http://your_username:your_strong_password@127.0.0.1:5984/obsidian-vault
- Remember what you named the vault -> in this case it’s just
obsidian-vault - From the docker container within the app, open quick actions and select the
5984port option. Then append to the url suffix “_utils”. This should bring you to the login screen for CouchDb. Use the login from the environment variables from earlier. Go to the gear / config settings, Go to CORS. And enable it. THIS IS VITAL FOR IOS. You can select All Domains.
Tailscale using Docker
- First, go into the tailscale console in your browser:
- Go to the DNS tab, enable HTTPS Certificates (at the bottom).
- Go to the settings tab, go to Personal Settings > Keys > Auth keys > Generate auth key. Name it whatever (e.g. “NAS”), copy and save the
key. Expiration doesn’t matter here, this gets consumed upon login
- Within docker shared folder, create tailscale directory
- Install docker image tailscale and instantiate container with the following tweaks to default settings: auto restart on, network mode host, privelleged mode ON, under Volume settings map the tailscale docker shared folder to
/var/lib/tailscalewith read/write perms. For environment variables, addTS_STATE_DIR->/var/lib/tailscaleandTS_AUTHKEY-><your key generated from tailscale console> - Make sure you have SSH enabled for connections, in UGreen its under Control Panel > Terminal. For reference, I only turned it on for this. You can probably get around this in other ways but this was easiest for me especially since I wasn’t on the local network.
- SSH into the NAS and run the following:
sudo docker ps | grep tailscale–> Grab the container idsudo docker exec -it <tailscale-container-name> tailscale serve --bg <HOST PORT for the Container's 5984 port>–> This enables the tailscale HTTPS servingsudo docker exec -it <tailscale-container-name> tailscale serve status–> Verify the active routing rule, grab the<address>.ts.netfor ease-of-use for later.
- Disconnect SSH, feel free to disable SSH from the control panel now if you wish.
Obsidian Setup:
- Go into settings > Community Plugins > enable them > search > Install “Self hosted Livesync”
- Feel free to enter an end-to-end encryption passphrase for extra security points
- Select CouchDB as the backend
- enter the
https://...ts.netlink from earlier - enter your couchdb admin user credentials
- enter your database name (I left it as
obsidian-vaultin the instructions here) - Select Use internal API
- And that’s mostly it, it will do a bunch of syncing now
- When it’s done, I recommend going back into the settings for the plugin > sync settings > Preset -> LiveSync. That way you get it actually syncing live instead of who-knows when.
IOS Setup:
- Same as the obsidian setup, just install the tailscale app, and follow the prompts (login, set up the vpn configuration in your phone settings)
Extra notes:
- I would recommend setting the tailscale expiry on the NAS device to never expire for convenience. I would guess you’d need shell into the container or re-instantiate it with new credentials or something otherwise, I’m not sure really. Just don’t want to deal with it.