NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.99k stars 14.01k forks source link

Nextcloud unhandled exception is thrown by nextcloud-setup.service relating to missing locales. #332025

Closed mannp closed 2 months ago

mannp commented 2 months ago

Describe the bug

An unhandled exception is thrown relating to locales while using en_GB locale.

Steps To Reproduce

Install nextcloud 29.0.4 on a machine using a en_GB locale.

      services.nextcloud = {
        enable = true;
        package = pkgs.nextcloud29;
        hostName = "nextcloud.domain.com";
        https = true;
        settings.overwriteProtocol = "https";
        autoUpdateApps.enable = true;
        autoUpdateApps.startAt = "05:00:00";
        config = {
          dbtype = "pgsql";
          dbuser = "nextcloud";
          dbhost = "/run/postgresql";
          dbname = "nextcloud";
          adminpassFile = config.sops.secrets."nextcloud/admin-password".path;
          adminuser = "admin";
        };
        /*settings = {
          overwriteprotocol = "https";
          default_phone_region = "GB";
          default_locale = "en_GB";
          force_locale = "en_GB"; 
          default_timezone = "Europe/London";
        };*/
        /*extraOptions = {
          default_locale = "en_GB";
          force_locale = "en_GB"; 
          default_timezone = "Europe/London";
        };*/
      };    

I have tried with the commented out config included, but they do not make a difference 
{ lib, ... }: {
  i18n = {
    defaultLocale = lib.mkDefault "en_GB.UTF-8";
    extraLocaleSettings = {
      LC_ADDRESS = "en_GB.UTF-8";
      LC_IDENTIFICATION = "en_GB.UTF-8";
      LC_MEASUREMENT = "en_GB.UTF-8";
      LC_MONETARY = "en_GB.UTF-8";
      LC_NAME = "en_GB.UTF-8";
      LC_NUMERIC = "en_GB.UTF-8";
      LC_PAPER = "en_GB.UTF-8";
      LC_TELEPHONE = "en_GB.UTF-8";
      LC_TIME = "en_GB.UTF-8";
      LC_ALL  = "en_GB.UTF-8";
      LANG  = "en_GB.UTF-8";
    };
    supportedLocales = [ "en_GB.UTF-8/UTF-8" ];
  };
  time.timeZone = "Europe/London";
}    

Expected behavior

Nextcloud install would proceed as expected

Screenshots

Not applicable

Additional context

Aug 03 16:56:58 gc3 systemd[1]: Starting nextcloud-setup.service...
Aug 03 16:56:58 gc3 nextcloud-setup-start[76211]: Nextcloud is not installed - only a limited number of commands are available
Aug 03 16:56:58 gc3 nextcloud-setup-start[76211]: Setting locale to en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8 failed.
Aug 03 16:56:58 gc3 nextcloud-setup-start[76211]: Please install one of these locales on your system and restart your web server.
Aug 03 16:56:58 gc3 nextcloud-setup-start[76211]: An unhandled exception has been thrown:
Aug 03 16:56:58 gc3 nextcloud-setup-start[76211]: Exception: Environment not properly prepared. in /nix/store/7aqs9f3c3pgaqcxlyyb03jg9jkvga2xr-nextcloud-29.0.4/lib/private/Console/Application.php:167
Aug 03 16:56:58 gc3 nextcloud-setup-start[76211]: Stack trace:
Aug 03 16:56:58 gc3 nextcloud-setup-start[76211]: #0 /nix/store/7aqs9f3c3pgaqcxlyyb03jg9jkvga2xr-nextcloud-29.0.4/console.php(101): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Aug 03 16:56:58 gc3 nextcloud-setup-start[76211]: #1 /nix/store/7aqs9f3c3pgaqcxlyyb03jg9jkvga2xr-nextcloud-29.0.4/occ(11): require_once('/nix/store/7aqs...')
Aug 03 16:56:58 gc3 nextcloud-setup-start[76211]: #2 {main}
Aug 03 16:56:58 gc3 systemd[1]: nextcloud-setup.service: Main process exited, code=exited, status=1/FAILURE
Aug 03 16:56:58 gc3 systemd[1]: nextcloud-setup.service: Failed with result 'exit-code'.
Aug 03 16:56:58 gc3 systemd[1]: Failed to start nextcloud-setup.service.

Notify maintainers

@schneefux @bachp @globin @Ma27

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
output here

Add a :+1: reaction to issues you find important.

Ma27 commented 2 months ago

I think the problem is supportedLocales: Nextcloud tries to do setlocale against different locales in its install process: https://github.com/nextcloud/server/blob/8511b89579b761798ea4f6ecf9257cad8d0bc462/lib/private/legacy/OC_Util.php#L931

I'm not sure why it's doing that in your case, but I'd suggest to not set supportedLocales and try again.

mannp commented 2 months ago

Thanks for taking the time to come back to me; that resolved it.

    supportedLocales = lib.mkMerge [
      (lib.mkIf (config.networking.hostName == "nc-server") [ "en_GB.UTF-8/UTF-8" "en_US.UTF-8/UTF-8" ])
      (lib.mkIf (config.networking.hostName != "nc-server") [ "en_GB.UTF-8/UTF-8" ])
    ];

Hopefully my logic is correct :)