TLDR
Install the appliance VM by Hansson IT, get rid of its default ZFS, provide storage to it from your TrueNAS, let it update itself automatically and effortlessly, use Cloudflare tunnel for remote access.
Background
There are dozens of threads about the many different ways Nextcloud (NC) can be set up with TrueNAS (or on TrueNAS). Many discussions are related to troubleshooting after a major update breaks everything. Surprisingly, I do not see much being mentioned about the combination of TrueNAS and this Nextcloud Appliance VM, which comes with a very polished automated easy-to-navigate installation script, and more importantly offers an automated weekly update script builtin. After ~1.5 years of using this approach for my home backup and storage needs, and experiencing essentially no issues, I think I can confidently recommend it for personal/home storage applications. I am going to use it for as long as the maintainer keeps it alive and free.
I do not mean to write a comprehensive step by step guide, as the main chunk of it is written by elsewhere by others (to whom I’m very grateful). I will only list the general setup and links to those guides + extra customization that I found helpful.
This NC VM is pre-configured to use ZFS, so as described below (and within the links), you will want to remove the ZFS settings since it’s being run on TrueNAS-provided storage.
For any first time user: please explore other methods too, e.g. see this very thorough write-up. My earlier experience was not positive with similar strategies I tried, including NC manual installation on a linux server machine, dockerized NC on linux machine, TrueNAS Scale official app, and the TrueCharts app. I have never tried the app on TrueNAS Core, or the AIO - I know there are happy users of those two as well. I do appreciate there is a need for upfront customization with this NC applicance VM, which the maintainer does not support obviously, but I don’t think it’s any more involved than the other approaches in the end.
Also I must say I’m no expert in either TrueNAS or NC, so if the more experienced users find some obvious issues with this setup, I hope they will mention them. The 1st two approaches are what I have used at home. The 3rd one I only tested it for a couple of weeks and it worked out nicely, but I don’t think I’ll want all my data to reside inside the VM with no easy way to directly access them if things go south
Three Approaches for using this NC VM with TrueNAS
I like the 1st two configurations, as with NFS I get the flexibility of accessing my NC data directly from TrueNAS if I need to.
A. Two machines, one runs TrueNAS, one runs NC VM (in my case the former is TrueNAS Core and the latter is a Proxmox server)
Make a dataset and share it via NFS for use by your NC VM.
Download the VM image from NC VM’s website (Nextcloud VM), put it on your hypervisor (in my case Proxmox VE), reserve an IP for it in your network. Do NOT initiate the installation script on the VM yet.
Modify the VM’s data mount from its pre-configured virtual disk to the NFS share you created for this.
Remove the VM’s ZFS configurations as your TrueNAS will provide you with the ZFS benefits. Detailed tutorial provided here, but I would only follow its first 9 steps then do the tweaks below.
Before making the changes in the link above, take a full copy of all the contents of the /mnt/ncdata
in the fresh VM, not just .ocdata
, so you can put them back after switching /mnt/ncdata
to your NFS share. This will ensure you won’t wreck the installation script. Instead of adding the NFS share to /etc/fstab
I found it more reliable to configure auto-mounting by creating a service to run on VM startup with some delay, to allow all network services to be up and running before the share is mounted. You can do so by creating a script to mount your NFS share on startup, e.g.:
sudo nano /usr/local/bin/mount_my_truenas_nfs.sh
The script would be something like below, assuming you use nfs4 - you could optimize the NFS mount command by adding options as needed.
#!/bin/bash
sleep 15
mount -t nfs4 <Your_trueNAS_IP>:/mnt/yourpool/yourdataset /mnt/ncdata
Make it executable
sudo chmod +x /usr/local/bin/mount_my_truenas_nfs.sh
Make a systemd service to run the script on startup.
sudo nano /etc/systemd/system/mount_my_truenas_nfs.service
The content would something like:
[Unit]
Description=Mount TrueNAS NFS Share
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/mount_my_truenas_nfs.sh
[Install]
WantedBy=default.target
Enable your service for the auto-mounting
sudo systemctl start mount-nfs.service
sudo systemctl status mount-nfs.service
sudo systemctl enable mount-nfs.service
Now reboot your VM and return all the initial contents of /mnt/ncdata
to it. Make sure /mnt/ncdata is owned by www-data:www-data
recursively.
Log out, log back in, and initiate the installation script (it will prompt you for root password and begins the script). It’s a seamless process.
I tend to not install many integrations when doing this for the 1st time to keep it light, and come back to add things in the future if I need to.
Be sure to opt for automated weekend update script! You can of course turn it on later too.
Setup your desired security, e.g. by addint TOTP app inside NC and setting up your 2FA for login.
If you have data to populate in it, simply rsync them to your NFS share under the directory they’re supposed to be in, and run a scan:
sudo -u www-data php /var/www/nextcloud/occ files:scan --all
If you have a domain, you can use a free account on Cloudflare and open a tunnel to either your VM or another VM or container on your hypervisor, so you can access your NC remotely, without the need for opening ports on your router or configuring a reverse proxy on your machine. If you take this route, you must add your domain to your NC VM’s trusted domain by editing the config.php:
sudo nano /var/www/nextcloud/config/config.php
Add to the array of trusted domains, e.g.
<yourcname.yourdomain.com>
B. Single machine running a hypervisor (both NC and TrueNAS are virtualized)
Exactly as method 1. Though be sure to read the forum on how to virtualize TrueNAS safely, you will need an HBA card to pass through to the TrueNAS VM.
C. Single machine - run NC as a VM on TrueNAS Scale running on bare metal
Again very similar to previous setups, except instead of mounting an NFS share, you create ZVOLs on TrueNAS Scale for your NC VM, and modify the data ZVOL’s virtual disk inside the VM to match your needs, i.e. expand it from its default 100 GB to whatever size you allocated to your ZVOL. Similar to approach 1 you get rid of ZFS file system in the VM since that’s taken care of by your host (i.e. TrueNAS Scale). Detailed steps are provided in this post. I recently added a comment there too about removing ZFS, so please read that also.
If you like to do this, consider creating a script on your TrueNAS host to shutdown this VM before snapshots of your ZVOLs are taken, as opposed to saving snapshots while the VM is running. This should help mitigate the risk of corrupting your VM in case a roll back becomes necessary.