Problem with services.nextcloud

Hi, I am new here and tried to setup the nextcloud-service on NixOs 19.09. Unfortunately I only got errormessages like this one:

Mär 15 20:22:35 debian-Nextcloud sudo[1107]:     root : TTY=unknown ; PWD=/nix/store/3dvvw2zsazdh0y9rby01aibpjdz2adfj-nextcloud-16.0.8 ; USER=nextcloud ; ENV=NEXTCLOUD_CONFIG_DIR=/var/lib/nextcloud/config ; COMMAND=/nix/store/gz5dizli5m1cx0wjnspgcwzgsl5m9fqs-php-7.3.15/bin/php -c /nix/store/lmyfpp0p3rfi4zbz1cp4i6ivp9lfgp37-php.ini occ upgrade...
Mär 15 20:22:35 debian-Nextcloud sudo[1107]: pam_unix(sudo:session): session opened for user nextcloud by (uid=0)
Mär 15 20:22:35 debian-Nextcloud hq13v29af5zwkzk027p1p7a2bif7v58i-unit-script-nextcloud-setup-start[1101]: Nextcloud is not installed - only a limited number of commands are available
Mär 15 20:22:35 debian-Nextcloud hq13v29af5zwkzk027p1p7a2bif7v58i-unit-script-nextcloud-setup-start[1101]:                                      
Mär 15 20:22:35 debian-Nextcloud hq13v29af5zwkzk027p1p7a2bif7v58i-unit-script-nextcloud-setup-start[1101]:   Command "upgrade" is not defined.
Mär 15 20:22:35 debian-Nextcloud hq13v29af5zwkzk027p1p7a2bif7v58i-unit-script-nextcloud-setup-start[1101]:                                      
Mär 15 20:22:35 debian-Nextcloud sudo[1107]: pam_unix(sudo:session): session closed for user nextcloud
Mär 15 20:22:35 debian-Nextcloud systemd[1]: nextcloud-setup.service: Main process exited, code=exited, status=1/FAILURE
Mär 15 20:22:35 debian-Nextcloud systemd[1]: nextcloud-setup.service: Failed with result 'exit-code'.
Mär 15 20:22:35 debian-Nextcloud 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
$ uname -a
Linux debian-Nextcloud 4.19.109 #1-NixOS SMP Wed Mar 11 13:15:13 UTC 2020 x86_64 GNU/Linux

I already tested nginx and postgresql successfully and red the manual twice.
There seems to be a problem with occ upgrade.

How can I solve the problem?

Could you post some related configuration that you have used?

Here my configuration:

$ cat /etc/nixos/nextcloud.nix

{ config, pkgs, ... }:
{

  services.nextcloud = {
    enable = true;
    hostName = "www.my-example-domain.tld";
    nginx.enable = true;
    config = {
      dbtype = "pgsql";
      dbuser = "nextcloud";
      dbhost = "/run/postgresql"; # nextcloud will add /.s.PGSQL.5432 by itself
      dbname = "nextcloud";
      dbpassFile = "/etc/nixos/nextcloud-psql-pw";
      adminpassFile = "/etc/nixos/nextcloud-pw";
      adminuser = "Admin";
    };
    # autoUpdateApps = true;
    maxUploadSize = "20G";
  };

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

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

  services.nginx = {
    enable = true;
    virtualHosts = {
      "www.my-example-domain.tld" = {
         forceSSL = true;
         enableACME = true;
         locations."/" = {
           root = "/var/www";
        };
      };
    };
  };

  networking.firewall.allowedTCPPorts = [ 80 443 ];
}

Hm, the error is still cryptic to me…

One thing I’ve noticed is that you set dbpassFile, but you are using Unix authentication. Maybe you need to remove this one.

The other thing I could recommend is, if this is a fresh installation and you do not mind starting over, to clean up files and database. Maybe the installation didn’t finish well, but it created the config.php file and thus the installation is not running anymore (Source).

Hi joko,

I tried so (1. commenting out all the stuff in the NixOs-Configuration file 2. nixos-rebuild switch 3. nix-collect-garbage 4. restart 5. another nixos-rebuild) but the problem still exists. After deleting the nextcloud-database in Postgresql I got the following errormessage:

Mär 15 22:04:29 debian-Nextcloud ffa0f0xgw0swkbysa8yk2jjx3yxgp47j-unit-script-nextcloud-setup-start[1675]: Nextcloud is not installed - only a limited number of commands are available
Mär 15 22:04:29 debian-Nextcloud Nextcloud[1682]: {no app in context} Error occurred while checking PostgreSQL version, assuming >= 9
Mär 15 22:04:29 debian-Nextcloud Nextcloud[1682]: {no app in context} {"Exception":"Doctrine\\DBAL\\DBALException","Message":"Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] FATAL:  database \"nextcloud\" does not exist","Code":0,"Trace":[{"file":"\/nix\/store\/3dvvw2zsazdh0y9rby01aibpjdz2adfj-nextcloud-16.0.8\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Connection.php","line":1065,"function":"connect","class":"OC\\DB\\Connection","type":"->","args":[]},{"file":"\/nix\/store\/3dvvw2zsazdh0y9rby01aibpjdz2adfj-nextcloud-16.0.8\/lib\/private\/DB\/Connection.php","line":216,"function":"executeUpdate","class":"Doctrine\\DBAL\\Connection","type":"->","args":["SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED",[],[]]},{"file":"\/nix\/store\/3dvvw2zsazdh0y9rby01aibpjdz2adfj-nextcloud-16.0.8\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Connection.php","line":710,"function":"executeUpdate","class":"OC\\DB\\Connection","type"…
Mär 15 22:04:29 debian-Nextcloud ffa0f0xgw0swkbysa8yk2jjx3yxgp47j-unit-script-nextcloud-setup-start[1675]:                                      
Mär 15 22:04:29 debian-Nextcloud ffa0f0xgw0swkbysa8yk2jjx3yxgp47j-unit-script-nextcloud-setup-start[1675]:   Command "upgrade" is not defined.
Mär 15 22:04:29 debian-Nextcloud ffa0f0xgw0swkbysa8yk2jjx3yxgp47j-unit-script-nextcloud-setup-start[1675]:                                      
Mär 15 22:04:29 debian-Nextcloud sudo[1681]: pam_unix(sudo:session): session closed for user nextcloud
Mär 15 22:04:29 debian-Nextcloud systemd[1]: nextcloud-setup.service: Main process exited, code=exited, status=1/FAILURE
Mär 15 22:04:29 debian-Nextcloud systemd[1]: nextcloud-setup.service: Failed with result 'exit-code'.
Mär 15 22:04:29 debian-Nextcloud 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

I hope that helps.

Now I tried with sqllite instead of psql. It doesn’t work too.
Here the error messages:

Mär 15 22:18:19 debian-Nextcloud sudo[2996]:     root : TTY=unknown ; PWD=/nix/store/3dvvw2zsazdh0y9rby01aibpjdz2adfj-nextcloud-16.0.8 ; USER=nextcloud ; ENV=NEXTCLOUD_CONFIG_DIR=/var/lib/nextcloud/config ; COMMAND=/nix/store/gz5dizli5m1cx0wjnspgcwzgsl5m9fqs-php-7.3.15/bin/php -c /nix/store/lmyfpp0p3rfi4zbz1cp4i6ivp9lfgp37-php.ini occ upgrade...
Mär 15 22:18:19 debian-Nextcloud sudo[2996]: pam_unix(sudo:session): session opened for user nextcloud by (uid=0)
Mär 15 22:18:19 debian-Nextcloud ckwhi3i3bm3ic4k38i6nxk56l4kf0f67-unit-script-nextcloud-setup-start[2990]: Nextcloud is not installed - only a limited number of commands are available
Mär 15 22:18:19 debian-Nextcloud ckwhi3i3bm3ic4k38i6nxk56l4kf0f67-unit-script-nextcloud-setup-start[2990]:                                      
Mär 15 22:18:19 debian-Nextcloud ckwhi3i3bm3ic4k38i6nxk56l4kf0f67-unit-script-nextcloud-setup-start[2990]:   Command "upgrade" is not defined.
Mär 15 22:18:19 debian-Nextcloud ckwhi3i3bm3ic4k38i6nxk56l4kf0f67-unit-script-nextcloud-setup-start[2990]:                                      
Mär 15 22:18:19 debian-Nextcloud sudo[2996]: pam_unix(sudo:session): session closed for user nextcloud
Mär 15 22:18:19 debian-Nextcloud systemd[1]: nextcloud-setup.service: Main process exited, code=exited, status=1/FAILURE
Mär 15 22:18:19 debian-Nextcloud systemd[1]: nextcloud-setup.service: Failed with result 'exit-code'.
Mär 15 22:18:19 debian-Nextcloud 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

Have you tried cleaning up the files, too? Everything on /var/lib/nextcloud.

Thanks for the advice (cleaning the nextcloud-folder and drop the nextcloud-psql-database and nixos-rebuild of course).
With ´sqllite´ instead ´pgsql´ set as database it seems to work (no errormessage so far and the loginscreen appears).
But with Postgresql-Db set I get the following errormessage:

Mär 17 22:04:50 debian-Nextcloud Nextcloud[3426]: {no app in context} Error occurred while checking PostgreSQL version, assuming >= 9
Mär 17 22:04:50 debian-Nextcloud Nextcloud[3426]: {no app in context} {"Exception":"Doctrine\\DBAL\\DBALException","Message":"Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] FATAL:  database \"nextcloud\" does not exist","Code":0,"Trace":[{"file":"\/nix\/store\/3dvvw2zsazdh0y9rby01aibpjdz2adfj-nextcloud-16.0.8\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Connection.php","line":1065,"function":"connect","class":"OC\\DB\\Connection","type":"->","args":[]},{"file":"\/nix\/store\/3dvvw2zsazdh0y9rby01aibpjdz2adfj-nextcloud-16.0.8\/lib\/private\/DB\/Connection.php","line":216,"function":"executeUpdate","class":"Doctrine\\DBAL\\Connection","type":"->","args":["SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED",[],[]]},{"file":"\/nix\/store\/3dvvw2zsazdh0y9rby01aibpjdz2adfj-nextcloud-16.0.8\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Connection.php","line":710,"function":"executeUpdate","class":"OC\\DB\\Connection","type"…
Mär 17 22:04:50 debian-Nextcloud Nextcloud[3426]: {no app in context} {"Exception":"Doctrine\\DBAL\\Exception\\DriverException","Message":"An exception occurred while executing 'CREATE DATABASE nextcloud OWNER nextcloud':\n\nSQLSTATE[42501]: Insufficient privilege: 7 ERROR:  permission denied to create database","Code":0,"Trace":[{"file":"\/nix\/store\/3dvvw2zsazdh0y9rby01aibpjdz2adfj-nextcloud-16.0.8\/3rdparty\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/DBALException.php","line":184,"function":"convertException","class":"Doctrine\\DBAL\\Driver\\AbstractPostgreSQLDriver","type":"->","args":["An exception occurred while executing 'CREATE DATABASE nextcloud OWNER nextcloud':\n\nSQLSTATE[42501]: Insufficient privilege: 7 ERROR:  permission denied to create database",{"errorInfo":["42501",7,"ERROR:  permission denied to create database"],"__class__":"Doctrine\\DBAL\\Driver\\PDOException"}]},{"file":"\/nix\/store\/3dvvw2zsazdh0y9rby01aibpjdz2adfj-nextcloud-16.0.8\/3rdparty\/doctrine\/dbal\/lib\…
Mär 17 22:04:50 debian-Nextcloud Nextcloud[3426]: {no app in context} Error trying to connect as "postgres", assuming database is setup and tables need to be created
Mär 17 22:04:50 debian-Nextcloud ffa0f0xgw0swkbysa8yk2jjx3yxgp47j-unit-script-nextcloud-setup-start[3418]: Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] FATAL:  database "nextcloud" does not exist
Mär 17 22:04:50 debian-Nextcloud ffa0f0xgw0swkbysa8yk2jjx3yxgp47j-unit-script-nextcloud-setup-start[3418]:  ->
Mär 17 22:04:50 debian-Nextcloud sudo[3425]: pam_unix(sudo:session): session closed for user nextcloud
Mär 17 22:04:50 debian-Nextcloud systemd[1]: nextcloud-setup.service: Main process exited, code=exited, status=1/FAILURE
Mär 17 22:04:50 debian-Nextcloud systemd[1]: nextcloud-setup.service: Failed with result 'exit-code'.
Mär 17 22:04:50 debian-Nextcloud 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

With sqlite as db it seems to work but I can’t login.
I tried the adminuser and adminpass used in the configuration but it isn’t accepted. (I tried the password as plaintext and hashed with mkpasswd -m sha-512)

You specified user nextcloud but the error message says user postgres could not log in.
I just run into the same issue with NextCloud in Docker.
Could you figure it out in the meantime?

I don’t know if it’s related, but in my case I had some spaces in my password, which broke the install with two error messages, at the first compilation it was Too many arguments, expected arguments "command". and then Command "upgrade" is not defined. . See this issue service.nextcloud.config.adminpassFile doesn't accept space-separated passwords · Issue #49487 · NixOS/nixpkgs · GitHub. To fix it, remove the password and delete the folder:

rm -rf /var/lib/nextcloud/
1 Like