Nextcloud passwords crashes the server dramatically

I just started self-hosting my own Nextcloud instance and am once again marveling at the beauty of NixOS. However, when I try to enable the passwords app via the web panel or the nextcloud-occ command, I receive a “500 Internal Server Error” response. Other apps work without a problem. Here are my journalctl logs:


Jul 12 22:16:47 myhostname Nextcloud[1325]: {"reqId":"iC4m8zhqdVXwKhXJ1091","level":3,"time":"2025-07-12T22:16:47+00:00","remoteAddr":"2a02:2455:8254:b000:ff29:4400:a022:69f9","user":"god","app":"PHP","method":"GET","url":"/apps/dashboard/","message":"Cannot redeclare nix_decode_json_file() (previously declared in /nix/store/lp6a3s7gyqi1c1f7rynp52fc7p8q92rb-nextcloud-config.php:3) at /nix/store/lp6a3s7gyqi1c1f7rynp52fc7p8q92rb-nextcloud-config.php#3","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0","version":"31.0.6.2","data":{"app":"PHP"}}
Jul 12 22:16:47 myhostname nginx[1446]: 2025/07/12 22:16:47 [error] 1446#1446: *591 FastCGI sent in stderr: "PHP message: PHP Fatal error: Cannot redeclare nix_decode_json_file() (previously declared in /nix/store/lp6a3s7gyqi1c1f7rynp52fc7p8q92rb-nextcloud-config.php:3) in /nix/store/lp6a3s7gyqi1c1f7rynp52fc7p8q92rb-nextcloud-config.php on line 3" while reading response header from upstream, client: 2a02:2455:8254:b000:ff29:4400:a022:69f9, server: cloud.my-domain.de, request: "GET /apps/dashboard/ HTTP/2.0", upstream: "fastcgi://unix:/run/phpfpm/nextcloud.sock:", host: "cloud.my-domain.de"
Jul 12 22:16:58 myhostname systemd[1]: Starting nextcloud-cron.service...
Jul 12 22:16:58 myhostname systemd[1]: Started nextcloud-cron.service.
Jul 12 22:16:58 myhostname nextcloud-cron-start[7785]: PHP Fatal error: Cannot redeclare nix_decode_json_file() (previously declared in /nix/store/lp6a3s7gyqi1c1f7rynp52fc7p8q92rb-nextcloud-config.php:3) in /nix/store/lp6a3s7gyqi1c1f7rynp52fc7p8q92rb-nextcloud-config.php on line 3

It works again after disabling it.

It seems this problem has been around for some time now.
Here is a review of the Passwords app: Passwords - Apps - App Store - Nextcloud
Here is a question from the French forum: [Nextcloud] Erreur = Cannot redeclare nix_decode_json_file()

If you cannot help me here, where should I open an issue ticket? Should I do so in nixpkgs or nextcloud-passwords? …or both?

Thanks for your help!

Can you share your configuration? This looks like some messy state shenanigans, looks like your nextcloud-config.php is executed twice?

Thank you for your reply! I have dumbed down my original config and redacted my personal info here: nixos-config_copy/zeuss/configuration.nix at master · L-Zach/nixos-config_copy · GitHub

Tested it with a fresh reinstall on a hetzner cloud server and the issue persists.

You’re leaking your password into the nix store here: nixos-config_copy/zeuss/configuration.nix at master · L-Zach/nixos-config_copy · GitHub

This here is what I was wondering about: nixos-config_copy/zeuss/configuration.nix at master · L-Zach/nixos-config_copy · GitHub

While in theory it should be fine to use the app store, this opens up potential for nextcloud to screw things up. Could you try, for the sake of argument, to use the declarative app install?

Note that you can also use nixos-rebuild build-vm to build a VM you can run locally.

Using fetchNextcloudApp yields the same error. I tried it with both stable and unstable nixpkgs.

    extraApps = {
      passwords = pkgs.fetchNextcloudApp {
        appName = "passwords";
        appVersion = "2025.7.0";
        hash = "sha256-SVItAtFRO/CbZ203ZS86inCZ+ZpGy0NUS3y2Xj1b+LI=";
        license = "agpl3Plus";
        url = "https://git.mdns.eu/api/v4/projects/45/packages/generic/passwords/2025.7.0/passwords.tar.gz";
      };
    };
    extraAppsEnable = true;

Thanks for pointing out my leaking password and the nixos-rebuild build-vm command. I am still a beginner when it comes to Nix.

Fair enough, guess there’s not much to do but debug the actual nextcloud config. Can you have a read through/share the various nextcloud config files (notably /nix/store/lp6a3s7gyqi1c1f7rynp52fc7p8q92rb-nextcloud-config.php)?

I’d build your system and try it out myself, but I’m without a computer for the moment.

I tried using Nextcloud 30 instead of 31 and got the same result. I did not see any changes to the configuration files when I enabled or disabled the app, but I might have missed them. Only the database changes. Here is the configuration you asked for.

<?php

function nix_decode_json_file($file, $error) {
  if (!file_exists($file)) {
    throw new \RuntimeException(sprintf($error, $file));
  }
  $decoded = json_decode(file_get_contents($file), true);

  if (json_last_error() !== JSON_ERROR_NONE) {
    throw new \RuntimeException(sprintf("Cannot decode %s, because: %s", $file, json_last_error_msg()));
  }

  return $decoded;
}
$CONFIG = [
  'apps_paths' => [
    [ 'path' => '/nix/store/bbq2m3bzi7i8lpgf6jjf2c3j0zbgywvl-nextcloud-31.0.6-with-apps/apps', 'url' => '/apps', 'writable' => false ],
[ 'path' => '/nix/store/bbq2m3bzi7i8lpgf6jjf2c3j0zbgywvl-nextcloud-31.0.6-with-apps/store-apps', 'url' => '/store-apps', 'writable' => true ],

  ],
  'appstoreenabled' => true,
  'memcache.local' => '\OC\Memcache\APCu',
  'dbname' => 'nextcloud',
  'dbhost' => '/run/postgresql',
  'dbuser' => 'nextcloud',
  
  
  'dbtype' => 'pgsql',
  
];

$CONFIG = array_replace_recursive($CONFIG, nix_decode_json_file(
  "/nix/store/jmnb1qr7q8b99fivqa8vwh11v0is4r2n-nextcloud-settings.json",
  "impossible: this should never happen (decoding generated settings file %s failed)"
));

Opening an issue ticket in nixpkgs would be okay now, right?

Probably. It strikes me as odd that an app would trigger this. But it doesn’t look like anything is outright wrong. I suspect you’ll still have to do the debugging yourself, in either case.

I read your ticket on GitHub… I’m relieved that I’m not facing an unsolvable problem. For now, we have to wait, but a solution seems possible.
One last thing you didn’t mention. For users who already have passwords, the problem doesn’t occur.
So on my instance, I have users for whom it works perfectly and others who are stuck with a 500 error.

Wait & See