Could not use mysql or pgsql as db in Nextcloud package

Hi, I am in the process of migrating a TrueNAS server to Nixos. But I’m stuck with the installation of Nextcloud. Setting it up with the default database ‘sqlite’ works perfectly, but I would like to use mysql or pgsql. But that doesn’t seem to work. I’ve described all the details in this SO issue.

What I want to know is, does the Nextcloud package take care of setting up the desired database and the tables in it? Because my experience is that it doesn’t. I have to set everything up myself. I start the mysql myself, create the user manually in the console and also the tables in the db are not created by the package.

Lastly, I deleted /var/lib/nextcloud and /var/lib/mysql, but that doesn’t help either.

I would be happy if you could share some thoughts with me.
Rob

Try setting package = nextcloud29 and database.createLocally = true. This should create and setup the MySQL database without any additional intervention from you.

Your error messages show two different versions of nextcloud being called. For reference here is my setup:

# Nextcloud
{
  config,
  pkgs,
  sops,
  ...
}:{
  sops.secrets.nextcloud-admin-password = {
    # This has to be world readable because I can't set ACLs with sops-nix for the 
    #   alertmanager systemd dynamic user. TODO
    mode = "0444";
    owner = config.users.users.nextcloud.name;
    group = config.users.users.nextcloud.group;
  };
  users.users.nextcloud.extraGroups = ["users"];
  services.nginx.virtualHosts."host.com".listen = [ { addr = "127.0.0.1"; port = 8082; } ];
 
  services.nextcloud = {
    enable = true;
    package = pkgs.nextcloud29;
    hostName = "host.com";
    database.createLocally = true;
    configureRedis = true;
    config = {
      adminuser = "user";
      adminpassFile = "${config.sops.secrets.nextcloud-admin-password.path}";
      dbtype = "mysql";
      defaultPhoneRegion = "US";
      trustedProxies = ["127.0.0.1"];
    };
    extraOptions = {
      mail_smtpmode = "sendmail";
      mail_sendmailmode = "pipe";
      mysql.utf8mb4 = true;
    };
    maxUploadSize = "2G"; # also sets post_max_size and memory_limit
    phpOptions = {
      "opcache.interned_strings_buffer" = "16";
    };
  };

  services.traefik.dynamicConfigOptions.http.routers.nextcloud = {
    rule = "Host(`host.com`)";
    service = "nextcloud";
    middlewares = ["headers"];
    entrypoints = ["websecure"];
    tls = {
      certResolver = "le";
    };
  };
  services.traefik.dynamicConfigOptions.http.services.nextcloud = {
    loadBalancer = {
      servers = [
        {
          url = "http://localhost:8082";
        }
      ];
    };
  };
}

Hi and thank you very much for your answer.
Sadly to let the package build the database doesn’t work also. I’am running into the same problem.

I tried also to delete any state with: rm -r /var/lib/mysql /var/lib/nextcloud and than use the package again. See the full script here:

{ pkgs, ... }:
{
  services.nextcloud = {
    package = pkgs.nextcloud29;
    enable = true;
    hostName = "bfds";

    database.createLocally = true;
     config = {
       dbtype = "mysql"; 
       adminuser = "admin";
       adminpassFile = "/var/lib/nextcloud-pass-files/nc-admin-password";
     };
    extraApps = {
      inherit (pkgs.nextcloud29Packages.apps) cookbook;
    };
    extraAppsEnable = true;
  }; 
   networking.firewall.allowedTCPPorts = [ 80 443 ];
}

I think I found a solution, that works for me. I started with the bare minimum config (like before) but use explicit the nextcloud version 27 (and later upgrade to 29). It seems that every versions must be installed, beginning with the Verion 27. Only that one creates the needed database.

I’m glad you found a solution that worked. I did test this on my laptop (which doesn’t normally have nextcloud installed) and was able to get it to work with Nextcloud 29. I did have trouble at first, but after deleting /var/lib/nextcloud, /var/lib/redis-nextcloud and /var/lib/mysql and rebuilding it successfully completed the install.

 # Nextcloud
  environment.etc."ncpass".text = "testpass";
  services.nextcloud = {
    enable = true;
    package = pkgs.nextcloud29;
    hostName = "localhost";
    database.createLocally = true;
    configureRedis = true;
    appstoreEnable = true;
    config = {
      adminuser = "firecat53";
      adminpassFile = "/etc/ncpass";
      dbtype = "mysql";
    };
    settings = {
      default_phone_region = "US";
      mysql.utf8mb4 = true;
    };
  };
1 Like