# Nextcloud {#module-services-nextcloud}
[Nextcloud](https://nextcloud.com/) is an open-source,
self-hostable cloud platform. The server setup can be automated using
[services.nextcloud](#opt-services.nextcloud.enable). A
desktop client is packaged at `pkgs.nextcloud-client`.
The current default by NixOS is `nextcloud31` which is also the latest
major version available.
## Basic usage {#module-services-nextcloud-basic-usage}
Nextcloud is a PHP-based application which requires an HTTP server
([`services.nextcloud`](#opt-services.nextcloud.enable)
and optionally supports
[`services.nginx`](#opt-services.nginx.enable)).
For the database, you can set
[`services.nextcloud.config.dbtype`](#opt-services.nextcloud.config.dbtype) to
either `sqlite` (the default), `mysql`, or `pgsql`. The simplest is `sqlite`,
which will be automatically created and managed by the application. For the
last two, you can easily create a local database by setting
[`services.nextcloud.database.createLocally`](#opt-services.nextcloud.database.createLocally)
to `true`, Nextcloud will automatically be configured to connect to it through
socket.
A very basic configuration may look like this:
```nix
{ pkgs, ... }:
{
services.nextcloud = {
enable = true;
hostName = "nextcloud.tld";
database.createLocally = true;
config = {
dbtype = "pgsql";
adminpassFile = "/path/to/admin-pass-file";
};
};
networking.firewall.allowedTCPPorts = [ 80 443 ];
}
```
The `hostName` option is used internally to configure an HTTP
server using [`PHP-FPM`](https://php-fpm.org/)
and `nginx`. The `config` attribute set is
used by the imperative installer and all values are written to an additional file
to ensure that changes can be applied by changing the module's options.
In case the application serves multiple domains (those are checked with
[`$_SERVER['HTTP_HOST']`](https://www.php.net/manual/en/reserved.variables.server.php))
it's needed to add them to
[`services.nextcloud.settings.trusted_domains`](#opt-services.nextcloud.settings.trusted_domains).
Auto updates for Nextcloud apps can be enabled using
[`services.nextcloud.autoUpdateApps`](#opt-services.nextcloud.autoUpdateApps.enable).
## Common problems {#module-services-nextcloud-pitfalls-during-upgrade}
- **General notes.**
Unfortunately Nextcloud appears to be very stateful when it comes to
managing its own configuration. The config file lives in the home directory
of the `nextcloud` user (by default
`/var/lib/nextcloud/config/config.php`) and is also used to
track several states of the application (e.g., whether installed or not).
All configuration parameters are also stored in
{file}`/var/lib/nextcloud/config/override.config.php` which is generated by
the module and linked from the store to ensure that all values from
{file}`config.php` can be modified by the module.
However {file}`config.php` manages the application's state and shouldn't be
touched manually because of that.
::: {.warning}
Don't delete {file}`config.php`! This file
tracks the application's state and a deletion can cause unwanted
side-effects!
:::
::: {.warning}
Don't rerun `nextcloud-occ maintenance:install`!
This command tries to install the application
and can cause unwanted side-effects!
:::
- **Multiple version upgrades.**
Nextcloud doesn't allow to move more than one major-version forward. E.g., if you're on
`v16`, you cannot upgrade to `v18`, you need to upgrade to
`v17` first. This is ensured automatically as long as the
[stateVersion](#opt-system.stateVersion) is declared properly. In that case
the oldest version available (one major behind the one from the previous NixOS
release) will be selected by default and the module will generate a warning that reminds
the user to upgrade to latest Nextcloud *after* that deploy.
- **`Error: Command "upgrade" is not defined.`**
This error usually occurs if the initial installation