Help setting up NextCloud module - NextCloud not installed

I tried using the snippet from NixOS wiki and it didn’t work. Then I found another snippet from here The Holy Grail Nextcloud setup made easy by NixOS · Carlos Vaz and changed a few things. Now I’m getting a NextCloud not installed error when nextcloud-setup.service tries to boot.

warning: the following units failed: nextcloud-setup.service
× nextcloud-setup.service
     Loaded: loaded (/etc/systemd/system/nextcloud-setup.service; enabled; preset: ignored)
     Active: failed (Result: exit-code) since Thu 2025-02-20 18:33:13 JST; 368ms ago
 Invocation: b0da9989113c4321a593dba6a8710edc
    Process: 62747 ExecStart=/nix/store/5ki5899f46d8fckjl9bj56yk2cy4qa54-unit-script-nextcloud-setup-start/bin/nextcloud-setup-start (code=exited, status=1/FAILURE)
   Main PID: 62747 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
         IO: 17.7M read, 0B written
   Mem peak: 38.2M
        CPU: 220ms

Feb 20 18:33:13 PikaNix systemd[1]: Starting nextcloud-setup.service...
Feb 20 18:33:13 PikaNix nextcloud-setup-start[62761]: Nextcloud is not installed - only a limited number of commands are available
Feb 20 18:33:13 PikaNix nextcloud-setup-start[62761]:                                      
Feb 20 18:33:13 PikaNix nextcloud-setup-start[62761]:   Command "upgrade" is not defined.
Feb 20 18:33:13 PikaNix nextcloud-setup-start[62761]:                                      
Feb 20 18:33:13 PikaNix systemd[1]: nextcloud-setup.service: Main process exited, code=exited, status=1/FAILURE
Feb 20 18:33:13 PikaNix systemd[1]: nextcloud-setup.service: Failed with result 'exit-code'.
Feb 20 18:33:13 PikaNix systemd[1]: Failed to start nextcloud-setup.service.
Feb 20 18:33:13 PikaNix systemd[1]: nextcloud-setup.service: Consumed 220ms CPU time, 38.2M memory peak, 17.7M read from disk.
warning: error(s) occurred while switching to the new configuration

This is what the NextCloud section of my configuration.nix looks like now:

services.nextcloud = {
    enable = true;
    hostName = "localhost";
    # Need to manually increment with every major upgrade.
    package = pkgs.nextcloud29;
    # Let NixOS install and configure the database automatically.
    database.createLocally = true;
    # Increase the maximum file upload size to avoid problems uploading videos.
    maxUploadSize = "16G";
    https = true;
    
    autoUpdateApps.enable = true;
    extraAppsEnable = true;
    extraApps = with config.services.nextcloud.package.packages.apps; {
      # List of apps we want to install and are already packaged in
      # https://github.com/NixOS/nixpkgs/blob/59236c424f78565cddaf8dd24d3703de358496b8/pkgs/servers/nextcloud/packages/nextcloud-apps.json
      inherit (config.services.nextcloud.package.packages.apps) previewgenerator;

      # Custom app installation example.
      # cookbook = pkgs.fetchNextcloudApp rec {
      #   url = "https://github.com/nextcloud/cookbook/releases/download/v0.10.2/Cookbook-0.10.2.tar.gz";
      #   sha256 = "sha256-XgBwUr26qW6wvqhrnhhhhcN4wkI+eXDHnNSm1HDbP6M=";
      #   license = "MIT";
      # };
    };
    
    config = {
      dbtype = "pgsql";
      adminuser = "admin";
      adminpassFile = "/etc/nextcloudadminpass";
    };
  };

I personally don’t use the Nextcloud service but have you looked at the official manual?

https://nixos.org/manual/nixos/stable/#module-services-nextcloud

In addition I don’t know which wiki you used but it is recommended to use the official one, however that doesn’t mean it is totally accurate either:
https://wiki.nixos.org/wiki/Nextcloud

Hi, thank you for replying.

I initially looked through both pages but those snippets don’t work because of various missing configs. The link I posted got me furthest but still not there yet.

Hi, not sure about this error but you should try with the latest pkgs.nextcloud30

Thank you, I tried with 30 but it didn’t work either… I also tried removing then readding the configuration in case it was some sort of initialization error but it didn’t work…

Here’s my working Nextcloud config. You can ignore the sops stuff, traefik config and changing the nginx port assignment (had a conflicting service).

Make sure you clean out any residual configuration in /var/lib/nextcloud and any existing databases before you try again. This bit me once when I was first experimenting. The database config especially is not necessarily idempotent.