How to make TrueNAS home directory as Nextcloud users' data directory

Hi folks,

I’m planning to install Nextcloud on TrueNAS Scale OS.

The main goal in the installation process is to let Nextcloud work with TrueNAS users and have its data directory located there.

for example I have the user’s home directory structure in TrueNAS:

/mnt/tank/home
|_User1
|_User2
|_User3

I want these users to use their home directories in netxcloud instead of directory created elsewhere by Nextcloud installation.

So what steps do I have to complete in order to achieve this?

Thanks

AFAIK there is no way to integrate Nextcloud with underlying OS. You can use different single-sign-in sso options like oidc saml and ldap but is for login only. The data stored in Nextcloud remains separated and under the control of the application.

In general you should avoid tempering with NC storage from “outside” as the application obviously can not track changes and for this reason NC can not provide it’s added functionality over plain storage system like file versions, recycle bin etc…

I would ask this question at truenas forum as this is more related to their Nextcloud app.

1 Like

As @wwe mentioned it’s not the best idea to have other applications accessing and modifying the NC home directory but nevertheless here’s my suggestion how to do it:

NC has a structure of /nc-data-directory/username
Your home users stay in /mnt/tank/home/username

  1. You could set your NC Data directory to /mnt/tank/home (but that’s a highly stupid idea)

  2. You could set a symlink from /mnt/tank/home/username to /nc-data-directory/username .

But one main problem I see is permissions: Webserver obviously needs permission to read and write to user’s directories. Therefore you must put all your users in the same group as your webserver and then tinker around with ACLs.

What is your reason to have home directory + NC home at the same place?

Well,

The main reason is that I want the users to be organized. Mainly, I was expecting from nextcloud to use user’s folders, because otherwise each user must then move their files uploaded to nextcloud folder to their “native” folder.

For example, using Nextcloud app, I want to free up my mobile phone storage by uploading files directly to my TrueNAS folder instead of Nextcloud user folder. Because otherwise, I have to then move all these files from nextcloud user folder to TrueNAS user folder.

I found “External Stogate Support” app in Nextcloud and activated it, then mounted my user folder in nextcloud app. I was kinda happy at the beginning but then I’ve discovered a whole bunch of errors in nextcloud.log like:

“Undefined array key "attributes" at /var/www/html/apps/files_external/3rdparty/icewind/smb/src/Wrapped/Parser.php#155”
“Malformed state response from server”

WELL KNOWN BUG/ISSUE in nextcloud, that I can’t fix it TrueNAS environment.

Fighting continues…

Hi!

Here’s the method I used to achieve my goal.
Versions used:

TrueNAS-SCALE: 22.12.4.2
Nextcloud: 29.0.6_2.0.15
  1. Creating a dataset on TrueNAS:

I started by creating a specific dataset for each user on TrueNAS, setting up the appropriate permissions for the user and for www-data (the web server user).
2. Mounting the volume in Kubernetes on TrueNAS:

Then, I mounted this volume in the Kubernetes (K8s) application on TrueNAS for Nextcloud. This allows Nextcloud to directly access the user’s directory via the mounted volume.
3. Creating users in Nextcloud:

In Nextcloud, I created a new user. For existing users who already had files and folders in their home directory, I used the following command to copy the entire directory structure with the correct permissions:

	rsync -a /path/source/ /path/destination/
  1. Creating a symbolic link:

Next, I created a symbolic link between the user’s Nextcloud directory and the volume mounted from TrueNAS, ensuring that files are properly synchronized between the two:

	ln -s /share/truenas/user /var/www/html/data/user
  1. Final result:

Now, when I log in as a user in Nextcloud, everything seems normal: the user can see their usual files and folders. When I connect via SMB to the mounted TrueNAS directory (which is mounted as a volume on Docker), I can see the user’s directory, and I can add or modify files from either Nextcloud or the SMB share.
Drawbacks:

There are two downsides to this approach:

  • Nextcloud folder structure visible via SMB:
    In the SMB shared folder, you also see Nextcloud’s specific directory structure (like cache files, trash, and the files directory). It’s important to navigate to the files directory to access the user’s files, otherwise, it could cause unexpected behavior.

  • Slow file updates:
    When adding or deleting files via SMB, Nextcloud doesn’t immediately detect the changes. I believe it’s possible to adjust the cache settings in Nextcloud’s configuration file to fix this, but here’s what I did to work around the issue:

  • I use the following command to force Nextcloud to rescan the directories:

	su -s /bin/sh -c 'php /var/www/html/occ files:scan {USER} www-data

This command works perfectly after the scan. To automate this, a cron job can be set up on the host system (TrueNAS Scale) to run this command periodically within the container.