Nextcloud: Difference between revisions
→Configuration: 'dynamic' configuration |
added link and explanation for two-factor authentication |
||
| (16 intermediate revisions by 6 users not shown) | |||
| Line 3: | Line 3: | ||
This article extends the documentation in the [https://nixos.org/manual/nixos/stable/#module-services-nextcloud NixOS manual]. | This article extends the documentation in the [https://nixos.org/manual/nixos/stable/#module-services-nextcloud NixOS manual]. | ||
== | == Setup == | ||
A minimal example to get the latest Nextcloud version (for your specific NixOS release) running on localhost should look like this, replacing <code>PWD</code> with a 10+ char password that meets [https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_password_policy.html Nextcloud's default password policy]. | A minimal example to get the latest Nextcloud version (for your specific NixOS release) running on localhost should look like this, replacing <code>PWD</code> with a 10+ char password that meets [https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_password_policy.html Nextcloud's default password policy]. | ||
| Line 24: | Line 24: | ||
=== Apps === | === Apps === | ||
[https://github.com/NixOS/nixpkgs/blob/ | [https://github.com/NixOS/nixpkgs/blob/2852f35f477e0f55e68b5f5e6d5a92242c215efc/pkgs/servers/nextcloud/packages/31.json Some apps] (use the file named <code><version>.json</code>, where version is the installed Nextcloud version), which are already packaged on NixOS, can be installed directly with the following example configuration: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
| Line 50: | Line 50: | ||
inherit (config.services.nextcloud.package.packages.apps) news contacts calendar tasks; | inherit (config.services.nextcloud.package.packages.apps) news contacts calendar tasks; | ||
memories = pkgs.fetchNextcloudApp { | memories = pkgs.fetchNextcloudApp { | ||
url = "https://github.com/pulsejet/memories/releases/download/v6.2.2/memories.tar.gz"; | |||
hash = "sha256-Xr1SRSmXo2r8yOGuoMyoXhD0oPVm/0/ISHlmNZpJYsg="; | |||
license = "agpl3Only"; | |||
}; | }; | ||
| Line 115: | Line 115: | ||
</nowiki>}} | </nowiki>}} | ||
=== | === Data storage === | ||
Nextcloud stores metadata in the database and files either on a local filesystem, external storage, or in an object storage. | |||
==== Local filesystem ==== | |||
Using a filesystem with snapshot support, such as btrfs or zfs, may be useful for backup purposes | |||
=== | ==== External storage ==== | ||
https://docs.nextcloud.com/server/stable/admin_manual/configuration_files/external_storage_configuration_gui.html | |||
==== Object store ==== | |||
In this example we'll configure a local S3-compatible object store using Minio and connect it to Nextcloud | In this example we'll configure a local S3-compatible object store using Minio and connect it to Nextcloud | ||
| Line 176: | Line 170: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
mc | mc alias set minio http://localhost:9000 ${accessKey} ${secretKey} --api s3v4 | ||
mc mb minio/nextcloud | mc mb minio/nextcloud | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 206: | Line 200: | ||
=== Secrets management === | === Secrets management === | ||
Do not suply passwords, hashes or keys via | Do not suply passwords, hashes or keys via the settings option, since they will be copied into the world-readable Nix store. Instead reference a JSON file containing secrets using the <code>secretFile</code> option. | ||
< | <syntaxhighlight lang="nix"> | ||
services.nextcloud = { | services.nextcloud = { | ||
[...] | [...] | ||
secretFile = "/etc/nextcloud-secrets.json"; | secretFile = "/etc/nextcloud-secrets.json"; | ||
}; | }; | ||
</syntaxhighlight> | |||
</ | |||
Consider using a [[Comparison of secret managing schemes|secret management tool]] instead of referencing an unencrypted local secrets file. | Consider using a [[Comparison of secret managing schemes|secret management tool]] instead of referencing an unencrypted local secrets file. | ||
=== Dynamic configuration === | |||
Unfortunately, some options can only be set 'interactively' in the database, and not via the configuration file. One way to | Unfortunately, some options can only be set 'interactively' in the database (either through the nextcloud-occ command line tool or the web UI), and not via the configuration file. One way to manage them "semi-declaratively" is to register a systemd script to reset the options on each redeploy: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 246: | Line 229: | ||
wantedBy = [ "multi-user.target" ]; | wantedBy = [ "multi-user.target" ]; | ||
}; | }; | ||
</syntaxHighlight> | </syntaxHighlight>Of course this is not ideal: changes through the web interface or occ client are still possible but will be overwritten the next redeploy, and removing a line from the script will not remove it from the configuration. | ||
== Maintenance == | == Maintenance == | ||
| Line 268: | Line 251: | ||
No password is required. | No password is required. | ||
=== Migration === | |||
If you want to migrate your Nextcloud instance from one place to another, keep in mind: | |||
* Distribution-agnostic instructions are at https://docs.nextcloud.com/server/stable/admin_manual/maintenance/migrating.html | |||
* You can use the [https://search.nixos.org/options?show=services.nextcloud.secretFile services.nextcloud.secretFile] option to set secrets. Notably you'll likely want to inherit the following values from your old to your new instance: | |||
** [https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/config_sample_php_parameters.html#instanceid instanceid] | |||
** [https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/config_sample_php_parameters.html#passwordsalt passwordsalt] | |||
** [https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/config_sample_php_parameters.html#secret secret] | |||
* To be able to configure TLS for your new instance before you've updated your DNS record, you can use [[ACME#DNS challenge|ACME DNS Challenge]]. Don't forget to clear <code>acmeRoot</code>: | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
services.nginx.virtualHosts.${config.services.nextcloud.hostName} = { | |||
forceSSL = true; | |||
enableACME = true; | |||
# force DNS-01 validation | |||
acmeRoot = null; | |||
}; | |||
</nowiki>}} | |||
=== Backups === | |||
You should make backups of both the database and your storage. | |||
For the database, [https://search.nixos.org/options?show=services.mysqlBackup services.mysqlBackup] or [https://search.nixos.org/options?show=services.postgresqlBackup services.postgresqlBackup] may come in handy. For local storage backups, periodically taking a snapshot of a snapshot-enabled filesystem such as btrfs or zfs may be a good first step. Remember to also make off-site copies. | |||
== Clients == | == Clients == | ||
| Line 325: | Line 332: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
services.nginx.virtualHosts." | services.nginx.virtualHosts."${config.services.nextcloud.hostName}".listen = [ { addr = "127.0.0.1"; port = 8080; } ]; | ||
</nowiki>}} | </nowiki>}} | ||
=== Enable Two-factor authentication === | |||
Two-factor authentication can be enabled for your server via the administration interface in your browser. There is no way to declare this setting via nix configuration, so you should follow the [https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/two_factor-auth.html official documentation] to set up Two-factor authentication. | |||
=== Enable HEIC image preview === | === Enable HEIC image preview === | ||
HEIC image preview needs to be explicitly enabled. This is done by adjusting the <code>enabledPreviewProviders</code> option. Beside the default list of supported formats, add an additional line <code>"OC\\Preview\\HEIC"</code> for HEIC image support. | HEIC image preview needs to be explicitly enabled. This is done by adjusting the <code>enabledPreviewProviders</code> option. Beside the default list of supported formats, add an additional line <code>"OC\\Preview\\HEIC"</code> for HEIC image support. See also [https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#enabledpreviewproviders this list of preview providers] for additional file types. | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
| Line 350: | Line 361: | ||
</nowiki>}} | </nowiki>}} | ||
=== Run | === Run Nextcloud in a sub-directory === | ||
Say, you don't want to run nextcloud at <code>your.site/</code> but in a sub-directory <code>your.site/nextcloud/</code>. To do so, we are going to add more configurations to nextcloud and to nginx to [[Nginx#TLS_reverse_proxy|make]] it a [https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ reverse-proxy]. | Say, you don't want to run nextcloud at <code>your.site/</code> but in a sub-directory <code>your.site/nextcloud/</code>. To do so, we are going to add more configurations to nextcloud and to nginx to [[Nginx#TLS_reverse_proxy|make]] it a [https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ reverse-proxy]. | ||
| Line 475: | Line 486: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | == App specific configuration == | ||
=== Whiteboard === | |||
The [https://github.com/nextcloud/whiteboard Whiteboard app] requires a running backend server which is also packaged in NixOS.<syntaxhighlight lang="nix"> | |||
environment.etc."nextcloud-whiteboard-secret".text = '' | |||
JWT_SECRET_KEY=test123 | |||
''; | |||
services.nextcloud-whiteboard-server = { | |||
enable = true; | |||
settings.NEXTCLOUD_URL = "http://localhost"; | |||
secrets = [ /etc/nextcloud-whiteboard-secret ]; | |||
}; | |||
</syntaxhighlight>After applying the configuration configure the Nextcloud app to use it<syntaxhighlight lang="bash"> | |||
nextcloud-occ config:app:set whiteboard collabBackendUrl --value="http://localhost:3002" | |||
nextcloud-occ config:app:set whiteboard jwt_secret_key --value="test123" | |||
</syntaxhighlight> | |||
=== NextCloud Office === | === NextCloud Office === | ||
| Line 491: | Line 518: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== ONLYOFFICE === | |||
You need to install both a document server and the [https://apps.nextcloud.com/apps/onlyoffice ONLYOFFICE Nextcloud plug-in]. There are several ways to install onlyoffice: | You need to install both a document server and the [https://apps.nextcloud.com/apps/onlyoffice ONLYOFFICE Nextcloud plug-in]. There are several ways to install onlyoffice: | ||
===== services.onlyoffice ===== | ===== services.onlyoffice ===== | ||
Install the onlyoffice documentserver as described in [[ONLYOFFICE_DocumentServer]]. | |||
Point the app to the document server from within the Nextcloud UI ("Administration Settings" -> Administration -> ONLYOFFICE), and make sure the 'services.onlyoffice.jwtSecretFile points to a file containing the same key as entered in the configuration of the Nextcloud app. | |||
===== the documentserver_community Nextcloud app ===== | ===== the documentserver_community Nextcloud app ===== | ||