Nextcloud with mysql

Greetings to all!
My nextcloud config so far, adapted from the prevailing pgsql example:

{ pkgs, ... }:
{
  services.nextcloud = {
    enable = true;
    hostName = "nextcloud.local";
    nginx.enable = true;
    config = {
      dbtype = "mysql";
      dbuser = "nextcloud";
      dbname = "nextcloud";
      adminpassFile = "/pathto/nextcloud_admin_passfile";
      adminuser = "root";
    };
  };

  services.mysql = {
    enable = true;
    ensureDatabases = [ "nextcloud" ];
    ensureUsers = [
     { name = "nextcloud";
       ensurePermissions = { "nextcloud.*" = "ALL PRIVILEGES";};

     }
    ];
    package = pkgs.mariadb;
  };

  # ensure that the db is running *before* running the setup
  systemd.services."nextcloud-setup" = {
    requires = ["mysql.service"];
    after = ["mysql.service"];
  };

  networking.firewall.allowedTCPPorts = [ 80 443 ];
}
  1. It ain’t working:
warning: the following units failed: nextcloud-setup.service

● nextcloud-setup.service
   Loaded: loaded (/nix/store/mypj25db9x9fml19nrvnvahi6489jdkd-unit-nextcloud-setup.service/nextcloud-setup.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2020-10-06 14:56:17 CEST; 16ms ago
  Process: 24314 ExecStart=/nix/store/ihhp6g2l3xvfz9wvp1xvi7r8sh34dy1n-unit-script-nextcloud-setup-start (code=exited, status=1/FAILURE)
 Main PID: 24314 (code=exited, status=1/FAILURE)
       IP: 0B in, 0B out
      CPU: 121ms

Oct 06 14:56:17 nixos sudo[24320]:     root : TTY=unknown ; PWD=/nix/store/83lmfh5bh69zwnhz177rfzf1ikqvg806-nextcloud-18.0.7 ; USER=nextcloud ; ENV=NEXTCLOUD_CONFIG_DIR=/var/lib/nextcloud/config ; COMMAND=/nix/store/vq6zsvvn8hacwdj5i7ck03rkm7fj2rgs-php-7.3.20/bin/php -c /nix/store/vkg0hz5f0ymmhi421bpnbmvp7hw4m9fr-php.ini occ upgrade...
Oct 06 14:56:17 nixos sudo[24320]: pam_unix(sudo:session): session opened for user nextcloud by (uid=0)
Oct 06 14:56:17 nixos ihhp6g2l3xvfz9wvp1xvi7r8sh34dy1n-unit-script-nextcloud-setup-start[24314]: Nextcloud is not installed - only a limited number of commands are available
Oct 06 14:56:17 nixos ihhp6g2l3xvfz9wvp1xvi7r8sh34dy1n-unit-script-nextcloud-setup-start[24314]:                     
Oct 06 14:56:17 nixos ihhp6g2l3xvfz9wvp1xvi7r8sh34dy1n-unit-script-nextcloud-setup-start[24314]:   Command "upgrade" is not defined.
Oct 06 14:56:17 nixos ihhp6g2l3xvfz9wvp1xvi7r8sh34dy1n-unit-script-nextcloud-setup-start[24314]:                     
Oct 06 14:56:17 nixos sudo[24320]: pam_unix(sudo:session): session closed for user nextcloud
Oct 06 14:56:17 nixos systemd[1]: nextcloud-setup.service: Main process exited, code=exited, status=1/FAILURE
Oct 06 14:56:17 nixos systemd[1]: nextcloud-setup.service: Failed with result 'exit-code'.
Oct 06 14:56:17 nixos systemd[1]: Failed to start nextcloud-setup.service.
Hint: Some lines were ellipsized, use -l to show in full.
warning: error(s) occurred while switching to the new configuration
  1. I also tried

package = pkgs.mysql;

it still seems to use MariaDB…
Is someone out there with helpful hints?

I also tried the pgsql version to get nextcloud up&running, but I get the same error. I found a similar error on nextcloud-wiki, but I actually don’t know what I could do about it…

What are the contents of /var/lib/nextcloud/config (or more specifically: /var/lib/nextcloud/config/config.php)?

The error you’re getting looks very much like the configuration file is missing for some reason.

Yes, this is the case. I found an empty config.php…
This is my override.config.php:

<?php

$CONFIG = [
  'apps_paths' => [
    [ 'path' => '/var/lib/nextcloud/apps', 'url' => '/apps', 'writable' => false ],
    [ 'path' => '/var/lib/nextcloud/store-apps', 'url' => '/store-apps', 'writable' => true ],
  ],
  'datadirectory' => '/var/lib/nextcloud/data',
  'skeletondirectory' => '',
  'memcache.local' => '\OC\Memcache\APCu',
  'log_type' => 'syslog',
  'log_level' => '2',

  'dbname' => 'nextcloud',
  'dbhost' => '/run/postgresql',

  'dbuser' => 'nextcloud',



  'dbtype' => 'pgsql',
  'trusted_domains' => ["nextcloud.local"],
  'trusted_proxies' => [],
];

Do I understand correctly, the content of the override file is generated automatically and, at some point it is copied into config.php?
Then the procedure is broken beforehand, I assume.
I checked permissions in nextcloud directory, it is all set to nextcloud:nginx, except for apps, which is a symlink to the store owned by root.

I hacked the content of the override into config.php manually and testet with nixos-rebuild, same here…

The override file is generated here:

… and it gets merged here:

So essentially it’s a way for the NixOS module to put partially read-only config values alongside the writable config as expected by Nextcloud. The latter btw. also contains the installed flag.

If this is a new installation and you don’t have data to lose, you could try removing /var/lib/nextcloud and retry. I’ve tried your configuration in a VM test before and it seemed to work. However, I tried it with NixOS 20.03, so it would be useful to know your exact NixOS version.

1 Like

Thank you for your advice.
I emptied the nextcloud directory and did another rebuild, now the nextcloud-setup service is up! My guess about what happend is, I had a file for the admin password, when first running nixos-rebuild, there seems to have been an issue with that so the install went astray, leaving the empty config.php behind. I corrected the issue with that root password, but the remnants of the first effort to install nextcloud prevented all succeeding rebuilds from being successful.