Nextcloud issues with shared folders

Hello, I recently migrated the data folder and database of an existing Nextcloud (Ubuntu snap solution) instance into a NixOS Nextcloud instance.

When testing I discovered that I get permission errors when accessing files in shared folders.
The relevant configuration:

{
  lib,
  pkgs,
  ...
}:

{
  # Nextcloud settings.
  services.nextcloud.enable = true;
  services.nextcloud.hostName = "localhost";
  services.nextcloud.config.dbtype = "mysql";
  services.nextcloud.config.dbname = "nextcloud"; # Using the default.
  services.nextcloud.package = pkgs.nextcloud34;
  services.nextcloud.maxUploadSize = "512M"; # Using the default.
  services.nextcloud.database.createLocally = true;

  systemd.services."phpfpm-nextcloud".serviceConfig.ReadWritePaths = [
    "/var/lib/nextcloud/data"
  ];

  # Nextcloud credentials.
  services.nextcloud.config.adminuser = "admin";
  # Initial admin password, used only at install time.
  services.nextcloud.config.adminpassFile = builtins.toFile "initial-nextcloud-admin-password" ''
    NextCloudInitialPwd
  '';

  # Nextcloud apps.
  services.nextcloud.extraApps = {
    # Present in nixpkgs.
    inherit (pkgs.nextcloud34Packages.apps)
      calendar
      collectives
      contacts
      files_automatedtagging
      groupfolders
      guests
      notes
      spreed;

    # Not present in nixpkgs.
    richdocumentscode = pkgs.fetchNextcloudApp {
      url     = "https://github.com/CollaboraOnline/richdocumentscode/releases/download/26.4.104/richdocumentscode.tar.gz";
      hash    = "sha256-0EYu1q03/A2jPYkSemslcW1Lp9EaNBqPrCgYCbOeLs0=";
      license = lib.licenses.asl20.shortName;
    };
  };

  # PHP Runtime.
  services.nextcloud.phpPackage = pkgs.php84;

  # Open nextcloud ports in the firewall.
  networking.firewall.allowedTCPPorts = [
    80 # HTTP.
  ];

  # NEXTCLOUD.
  # Trusted nextcloud domains.
  services.nextcloud.settings.trusted_domains = [
    "192.168.0.136"
    "mydomain.com"
  ];

  # Extra nextcloud config. Inherited from the snap instance.
  services.nextcloud.settings = {
    "debug" = true;
    "instanceid" = "old_instance_id";
    "defaultapp" = "files";
    "secret" = "old_secret";
    "passwordsalt" = "old_password_salt";
  };

  users.groups.nextcloud = {
    gid = 992;
  };

  users.users.nextcloud = {
    uid = 994;
    group = "nextcloud";
  };

  # EXTERNAL MOUNTS.
  fileSystems."/var/lib/nextcloud/data" = {
    device = "nextcloud@192.168.0.148:/mnt/BigDump/nextcloud/data";
    fsType = "sshfs";
    options = [
      "nodev"                                             # Do not treat as unix device.
      "noatime"                                           # Do not register access time to win performance.
      "allow_other"                                       # Allow other ussers to access the mount.
      "reconnect"                                         # Reconnect after failure.
      "ServerAliveInterval=30"                            # Keep the connection alive by sending a keepalive packet every x seconds.
      "IdentityFile=/root/.ssh/id_ed25519"                # Local SSH client key for login.
      "idmap=user"                                        # Map remote user with local user uid and gid.
      "uid=${toString config.users.users.nextcloud.uid}"  # User id for the mounted file system.
      "gid=${toString config.users.groups.nextcloud.gid}" # Group id for the mounted file system.
    ];
  };

}

Symptoms when accessing a shared file:

journalctl -xeu phpfpm-nextcloud.service

aug 25 13:57:36 nixtcloud Nextcloud[946]: {"reqId":"ox1bPqqQof7CPFIVU12W","level":3,"time":"2026-08-25T11:57:36+00:00","remoteAddr":"192.168.0.215","user":"dse","app":"text","method":"PUT","url":"/apps/text/session/141709/create","scriptName":"/index.php","message":"{\"Exception\":\"OCP\\\\Files\\\\NotFoundException\",\"Message\":\"\",\"Code\":0,\"Trace\":[{\"file\":\"/nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/apps/text/lib/Service/ApiService.php\",\"line\":66,\"function\":\"getFileById\",\"class\":\"OCA\\\\Text\\\\Service\\\\DocumentService\",\"type\":\"->\"},{\"file\":\"/nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/apps/text/lib/Controller/SessionController.php\",\"line\":46,\"function\":\"create\",\"class\":\"OCA\\\\Text\\\\Service\\\\ApiService\",\"type\":\"->\",\"args\":[\"*** sensitive parameters replaced ***\"]},{\"file\":\"/nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/lib/private/AppFramework/Http/Dispatcher.php\",\"line\":165,\"function\":\"create\",\"class\":\"OCA\\\\Text\\\\Controller\\\\SessionController\",\"type\":\"->\",\"args\":[\"*** sensitive parameters replaced ***\"]},{\"file\":\"/nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/lib/private/AppFramework/Http/Dispatcher.php\",\"line\":78,\"function\":\"executeController\",\"class\":\"OC\\\\AppFramework\\\\Http\\\\Dispatcher\",\"type\":\"->\"},{\"file\":\"/nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/lib/private/AppFramework/App.php\",\"line\":137,\"function\":\"dispatch\",\"class\":\"OC\\\\AppFramework\\\\Http\\\\Dispatcher\",\"type\":\"->\"},{\"file\":\"/nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/lib/private/Route/Router.php\",\"line\":324,\"function\":\"main\",\"class\":\"OC\\\\AppFramework\\\\App\",\"type\":\"::\"},{\"file\":\"/nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/lib/base.php\",\"line\":1172,\"function\":\"match\",\"class\":\"OC\\\\Route\\\\Router\",\"type\":\"->\"},{\"file\":\"/nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/index.php\",\"line\":25,\"function\":\"handleRequest\",\"class\":\"OC\",\"type\":\"::\"}],\"File\":\"/nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/apps/text/lib/Service/DocumentService.php\",\"Line\":557,\"message\":\"No permission to access this file\",\"exception\":\"{\\\"class\\\":\\\"OCP\\\\Files\\\\NotFoundException\\\",\\\"message\\\":\\\"\\\",\\\"code\\\":0,\\\"file\\\":\\\"/nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/apps/text/lib/Service/DocumentService.php:557\\\",\\\"trace\\\":\\\"#0 /nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/apps/text/lib/Service/ApiService.php(66): OCA\\\\Text\\\\Service\\\\DocumentService->getFileById()\\\\n#1 /nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/apps/text/lib/Controller/SessionController.php(46): OCA\\\\Text\\\\Service\\\\ApiService->create()\\\\n#2 /nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/lib/private/AppFramework/Http/Dispatcher.php(165): OCA\\\\Text\\\\Controller\\\\SessionController->create()\\\\n#3 /nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/lib/private/AppFramework/Http/Dispatcher.php(78): OC\\\\AppFramework\\\\Http\\\\Dispatcher->executeController()\\\\n#4 /nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/lib/private/AppFramework/App.php(137): OC\\\\AppFramework\\\\Http\\\\Dispatcher->dispatch()\\\\n#5 /nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/lib/private/Route/Router.php(324): OC\\\\AppFramework\\\\App::main()\\\\n#6 /nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/lib/base.php(1172): OC\\\\Route\\\\Router->match()\\\\n#7 /nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/index.php(25): OC::handleRequest()\\\\n#8 {main}\\\"}\",\"CustomMessage\":\"No permission to access this file\"}","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:154.0) Gecko/20100101 Firefox/154.0","version":"34.0.3.2"}

I have checked filesystem permissions and there is no difference between files in my user folder where I do have access and my shared folder where I don’t have access.

Any hints to what I should check would be very helpful, thanks.

Reading the single log line you provided, the file in question would live here: /nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/apps/text/lib/Service/ApiService.php

Sooo…maybe reinstall the Nextcloud text App or recompile the complete app? It is definitely no Permission Problem (i have no idea how you come to that conclusion). The error is clearly stated as “Files\\NotFoundException“. So yeah, try reinstalling the nextcloud “text” app or rebuild the entire nix config (maybe even deleting `nix/store/1p22hhkvnsj697vj0ipzn1igim9hfw6w-nextcloud-34.0.3/` and doing a cheeky `nixos-rebuild` would work, but wouldn’t recommend it)

Thanks a lot for pointing that out. The error happens indeed in the text-app … when I disable the text app the error goes away but so does the features (which is expected). I tested in a VM with a fresh install and sat up similar conditions and the error is not reproducible, so I am thinking that there is something corrupted in the database…

And I tried running nextcloud-occ repair and scan commands but they don’t seem to help.
I will try migration again with a fresh db-dump

This won’t directly help you but note that migrating Nextcloud that way is hard, as can be seen in the Nextcloud All-in-One migration guide: all-in-one/migration.md at 6a895db00259aa94d94fd0db433720a3bf6aeed7 · nextcloud/all-in-one · GitHub There might be some useful tips in there.

Thanks a lot for the resources. I’ll review them before the production migration.

I finally found the root of all evil. It was because of the data stored in oc_storages table. I noticed that some entries were encrypted, actually hashed.
And I found out that the id column of that table had a limitation on 64 characters. The data in that column is used to map storage paths… so I had to lookup the paths on the old server which were like this: local::/var/snap/nextcloud/common/nextcloud/data/__groupfolders/17/ and then I hashed this value with: echo -n "local::/var/snap/nextcloud/common/nextcloud/data/__groupfolders/17/" | md5sum and optained the md5 sum fe548f1838215726892e26a3e2c7b666 which was in the oc_storage table.
Then I replaced the hash value with the data path of the new installation.
update oc_storages set id = 'local::/var/lib/nextcloud/data/__groupfolders/17/' where id = 'fe548f1838215726892e26a3e2c7b666';

The new value keeps the 64-char limit. Otherwise it needs to be md5-hashed.
Now I get why changing of datadir is often unadvised.

1 Like