Nextcloud with DataDir on network share

Hi!

I’m new to nixos and after setting up my desktop and laptop, I want to migrate my nextcloud server to nixos. I want the datadir on a network share. The nextcloud module is complaining about permissions. How must I mount the network share, so that the nextcloud module has the rights to use this share?

Here is the error:

warning: the following units failed: nextcloud-setup.service

× nextcloud-setup.service
     Loaded: loaded (/etc/systemd/system/nextcloud-setup.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Thu 2024-05-16 14:31:19 CEST; 297ms ago
    Process: 2773 ExecStart=/nix/store/9r0alp08jsmk8sbcb6knpv7cbb09v36z-unit-script-nextcloud-setup-start/bin/nextcloud-setup-start (code=exited, status=1/FAILURE)
   Main PID: 2773 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 191ms

Mai 16 14:31:19 marsellus systemd[1]: Starting nextcloud-setup.service...
Mai 16 14:31:19 marsellus nextcloud-setup-start[2900]: Nextcloud is not installed - only a limited number of commands are available
Mai 16 14:31:19 marsellus nextcloud-setup-start[2900]:                                      
Mai 16 14:31:19 marsellus nextcloud-setup-start[2900]:   Command "upgrade" is not defined.
Mai 16 14:31:19 marsellus nextcloud-setup-start[2900]:                                      
Mai 16 14:31:19 marsellus systemd[1]: nextcloud-setup.service: Main process exited, code=exited, status=1/FAILURE
Mai 16 14:31:19 marsellus systemd[1]: nextcloud-setup.service: Failed with result 'exit-code'.
Mai 16 14:31:19 marsellus systemd[1]: Failed to start nextcloud-setup.service.

And the same config works if pointed to a local DataDir?

Yes. When using default settings everything works.

Here’s the relevant nextcloud part:

services.nextcloud = {
  enable = true;
  package = pkgs.nextcloud28;
  ...
  datadir = "/nextcloud";

That’s the mount part:

fileSystems."/nextcloud" = {
    device = "//192.168.1.3/Daten/nextcloud";
    fsType = "cifs";
    options = let
      # this line prevents hanging on network split
      automount_opts = "x-systemd.automount,noauto,x-systemd.idle-timeout=60,x-systemd.device-timeout=5s,x-systemd.mount-timeout=5s";

    in ["${automount_opts},credentials=/home/specter/smb-secrets,uid=nextcloud,gid=nextcloud,file_mode=0777,dir_mode=0777,mfsymlinks"];
  };

OK, same happens when pointing the datadir to local folder. Createt folder /test and chown nextcloud:nextcloud. Pointing the datadir there resulted in same error:

warning: the following units failed: nextcloud-setup.service

× nextcloud-setup.service
     Loaded: loaded (/etc/systemd/system/nextcloud-setup.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Thu 2024-05-16 15:36:55 CEST; 531ms ago
    Process: 2789 ExecStart=/nix/store/hlxghwk8099kyadlqfh36jq6y43bagdv-unit-script-nextcloud-setup-start/bin/nextcloud-setup-start (code=exited, status=1/FAILURE)
   Main PID: 2789 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 202ms

Mai 16 15:36:55 marsellus systemd[1]: Starting nextcloud-setup.service...
Mai 16 15:36:55 marsellus nextcloud-setup-start[2810]: Nextcloud is not installed - only a limited number of commands are available
Mai 16 15:36:55 marsellus nextcloud-setup-start[2810]:                                      
Mai 16 15:36:55 marsellus nextcloud-setup-start[2810]:   Command "upgrade" is not defined.
Mai 16 15:36:55 marsellus nextcloud-setup-start[2810]:                                      
Mai 16 15:36:55 marsellus systemd[1]: nextcloud-setup.service: Main process exited, code=exited, status=1/FAILURE
Mai 16 15:36:55 marsellus systemd[1]: nextcloud-setup.service: Failed with result 'exit-code'.
Mai 16 15:36:55 marsellus systemd[1]: Failed to start nextcloud-setup.service.

OK, I’m giving up on that. The nixos nextcloud module seem to not work with datadir on mounted network share or even outside /var/lib/nextcloud.

So, is it possible to have the container method stored on a network share?