2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.nextcloud;
|
|
|
|
fpm = config.services.phpfpm.pools.nextcloud;
|
|
|
|
|
2021-10-14 00:43:12 +00:00
|
|
|
inherit (cfg) datadir;
|
|
|
|
|
2021-10-04 12:37:57 +00:00
|
|
|
phpPackage = cfg.phpPackage.buildEnv {
|
2021-02-05 17:12:51 +00:00
|
|
|
extensions = { enabled, all }:
|
|
|
|
(with all;
|
|
|
|
enabled
|
2021-04-25 03:57:28 +00:00
|
|
|
++ optional cfg.enableImagemagick imagick
|
2021-02-05 17:12:51 +00:00
|
|
|
# Optionally enabled depending on caching settings
|
|
|
|
++ optional cfg.caching.apcu apcu
|
|
|
|
++ optional cfg.caching.redis redis
|
|
|
|
++ optional cfg.caching.memcached memcached
|
|
|
|
)
|
|
|
|
++ cfg.phpExtraExtensions all; # Enabled by user
|
|
|
|
extraConfig = toKeyValue phpOptions;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
toKeyValue = generators.toKeyValue {
|
|
|
|
mkKeyValue = generators.mkKeyValueDefault {} " = ";
|
|
|
|
};
|
|
|
|
|
|
|
|
phpOptions = {
|
|
|
|
upload_max_filesize = cfg.maxUploadSize;
|
|
|
|
post_max_size = cfg.maxUploadSize;
|
|
|
|
memory_limit = cfg.maxUploadSize;
|
2021-03-09 03:18:52 +00:00
|
|
|
} // cfg.phpOptions
|
|
|
|
// optionalAttrs cfg.caching.apcu {
|
|
|
|
"apc.enable_cli" = "1";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
occ = pkgs.writeScriptBin "nextcloud-occ" ''
|
|
|
|
#! ${pkgs.runtimeShell}
|
|
|
|
cd ${cfg.package}
|
|
|
|
sudo=exec
|
|
|
|
if [[ "$USER" != nextcloud ]]; then
|
2020-06-18 07:06:33 +00:00
|
|
|
sudo='exec /run/wrappers/bin/sudo -u nextcloud --preserve-env=NEXTCLOUD_CONFIG_DIR --preserve-env=OC_PASS'
|
2020-04-24 23:36:52 +00:00
|
|
|
fi
|
2021-10-14 00:43:12 +00:00
|
|
|
export NEXTCLOUD_CONFIG_DIR="${datadir}/config"
|
2020-04-24 23:36:52 +00:00
|
|
|
$sudo \
|
|
|
|
${phpPackage}/bin/php \
|
2020-12-25 13:55:36 +00:00
|
|
|
occ "$@"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
inherit (config.system) stateVersion;
|
|
|
|
|
|
|
|
in {
|
2020-08-20 17:08:02 +00:00
|
|
|
|
|
|
|
imports = [
|
2021-10-11 16:52:03 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "nextcloud" "config" "adminpass" ] ''
|
|
|
|
Please use `services.nextcloud.config.adminpassFile' instead!
|
|
|
|
'')
|
|
|
|
(mkRemovedOptionModule [ "services" "nextcloud" "config" "dbpass" ] ''
|
|
|
|
Please use `services.nextcloud.config.dbpassFile' instead!
|
|
|
|
'')
|
2020-08-20 17:08:02 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "nextcloud" "nginx" "enable" ] ''
|
|
|
|
The nextcloud module supports `nginx` as reverse-proxy by default and doesn't
|
|
|
|
support other reverse-proxies officially.
|
|
|
|
|
|
|
|
However it's possible to use an alternative reverse-proxy by
|
|
|
|
|
|
|
|
* disabling nginx
|
|
|
|
* setting `listen.owner` & `listen.group` in the phpfpm-pool to a different value
|
|
|
|
|
|
|
|
Further details about this can be found in the `Nextcloud`-section of the NixOS-manual
|
|
|
|
(which can be openend e.g. by running `nixos-help`).
|
|
|
|
'')
|
2021-04-25 03:57:28 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "nextcloud" "disableImagemagick" ] ''
|
|
|
|
Use services.nextcloud.nginx.enableImagemagick instead.
|
|
|
|
'')
|
2020-08-20 17:08:02 +00:00
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
options.services.nextcloud = {
|
|
|
|
enable = mkEnableOption "nextcloud";
|
|
|
|
hostName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "FQDN for the nextcloud instance.";
|
|
|
|
};
|
|
|
|
home = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/nextcloud";
|
|
|
|
description = "Storage path of nextcloud.";
|
|
|
|
};
|
2021-10-14 00:43:12 +00:00
|
|
|
datadir = mkOption {
|
|
|
|
type = types.str;
|
2022-07-14 12:49:19 +00:00
|
|
|
default = config.services.nextcloud.home;
|
|
|
|
defaultText = literalExpression "config.services.nextcloud.home";
|
2021-10-14 00:43:12 +00:00
|
|
|
description = ''
|
|
|
|
Data storage path of nextcloud. Will be <xref linkend="opt-services.nextcloud.home" /> by default.
|
|
|
|
This folder will be populated with a config.php and data folder which contains the state of the instance (excl the database).";
|
|
|
|
'';
|
|
|
|
example = "/mnt/nextcloud-file";
|
|
|
|
};
|
|
|
|
extraApps = mkOption {
|
|
|
|
type = types.attrsOf types.package;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
Extra apps to install. Should be an attrSet of appid to packages generated by fetchNextcloudApp.
|
|
|
|
The appid must be identical to the "id" value in the apps appinfo/info.xml.
|
|
|
|
Using this will disable the appstore to prevent Nextcloud from updating these apps (see <xref linkend="opt-services.nextcloud.appstoreEnable" />).
|
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
maps = pkgs.fetchNextcloudApp {
|
|
|
|
name = "maps";
|
|
|
|
sha256 = "007y80idqg6b6zk6kjxg4vgw0z8fsxs9lajnv49vv1zjy6jx2i1i";
|
|
|
|
url = "https://github.com/nextcloud/maps/releases/download/v0.1.9/maps-0.1.9.tar.gz";
|
|
|
|
version = "0.1.9";
|
|
|
|
};
|
|
|
|
phonetrack = pkgs.fetchNextcloudApp {
|
|
|
|
name = "phonetrack";
|
|
|
|
sha256 = "0qf366vbahyl27p9mshfma1as4nvql6w75zy2zk5xwwbp343vsbc";
|
|
|
|
url = "https://gitlab.com/eneiluj/phonetrack-oc/-/wikis/uploads/931aaaf8dca24bf31a7e169a83c17235/phonetrack-0.6.9.tar.gz";
|
|
|
|
version = "0.6.9";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
extraAppsEnable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Automatically enable the apps in <xref linkend="opt-services.nextcloud.extraApps" /> every time nextcloud starts.
|
|
|
|
If set to false, apps need to be enabled in the Nextcloud user interface or with nextcloud-occ app:enable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
appstoreEnable = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
example = true;
|
|
|
|
description = ''
|
|
|
|
Allow the installation of apps and app updates from the store.
|
|
|
|
Enabled by default unless there are packages in <xref linkend="opt-services.nextcloud.extraApps" />.
|
|
|
|
Set to true to force enable the store even if <xref linkend="opt-services.nextcloud.extraApps" /> is used.
|
|
|
|
Set to false to disable the installation of apps from the global appstore. App management is always enabled regardless of this setting.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.ints.between 0 4;
|
|
|
|
default = 2;
|
|
|
|
description = "Log level value between 0 (DEBUG) and 4 (FATAL).";
|
|
|
|
};
|
|
|
|
https = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Use https for generated links.";
|
|
|
|
};
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "Which package to use for the Nextcloud instance.";
|
2022-06-16 17:23:12 +00:00
|
|
|
relatedPackages = [ "nextcloud23" "nextcloud24" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-10-04 12:37:57 +00:00
|
|
|
phpPackage = mkOption {
|
|
|
|
type = types.package;
|
2022-06-16 17:23:12 +00:00
|
|
|
relatedPackages = [ "php80" "php81" ];
|
2021-10-04 12:37:57 +00:00
|
|
|
defaultText = "pkgs.php";
|
|
|
|
description = ''
|
|
|
|
PHP package to use for Nextcloud.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
maxUploadSize = mkOption {
|
|
|
|
default = "512M";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Defines the upload limit for files. This changes the relevant options
|
|
|
|
in php.ini and nginx if enabled.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
skeletonDirectory = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The directory where the skeleton files are located. These files will be
|
|
|
|
copied to the data directory of new users. Leave empty to not copy any
|
|
|
|
skeleton files.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
webfinger = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable this option if you plan on using the webfinger plugin.
|
|
|
|
The appropriate nginx rewrite rules will be added to your configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
phpExtraExtensions = mkOption {
|
|
|
|
type = with types; functionTo (listOf package);
|
|
|
|
default = all: [];
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "all: []";
|
2021-02-05 17:12:51 +00:00
|
|
|
description = ''
|
|
|
|
Additional PHP extensions to use for nextcloud.
|
|
|
|
By default, only extensions necessary for a vanilla nextcloud installation are enabled,
|
|
|
|
but you may choose from the list of available extensions and add further ones.
|
|
|
|
This is sometimes necessary to be able to install a certain nextcloud app that has additional requirements.
|
|
|
|
'';
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2021-02-05 17:12:51 +00:00
|
|
|
all: [ all.pdlib all.bz2 ]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
phpOptions = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {
|
|
|
|
short_open_tag = "Off";
|
|
|
|
expose_php = "Off";
|
|
|
|
error_reporting = "E_ALL & ~E_DEPRECATED & ~E_STRICT";
|
|
|
|
display_errors = "stderr";
|
|
|
|
"opcache.enable_cli" = "1";
|
|
|
|
"opcache.interned_strings_buffer" = "8";
|
|
|
|
"opcache.max_accelerated_files" = "10000";
|
|
|
|
"opcache.memory_consumption" = "128";
|
|
|
|
"opcache.revalidate_freq" = "1";
|
|
|
|
"opcache.fast_shutdown" = "1";
|
|
|
|
"openssl.cafile" = "/etc/ssl/certs/ca-certificates.crt";
|
|
|
|
catch_workers_output = "yes";
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Options for PHP's php.ini file for nextcloud.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
poolSettings = mkOption {
|
|
|
|
type = with types; attrsOf (oneOf [ str int bool ]);
|
|
|
|
default = {
|
|
|
|
"pm" = "dynamic";
|
|
|
|
"pm.max_children" = "32";
|
|
|
|
"pm.start_servers" = "2";
|
|
|
|
"pm.min_spare_servers" = "2";
|
|
|
|
"pm.max_spare_servers" = "4";
|
|
|
|
"pm.max_requests" = "500";
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Options for nextcloud's PHP pool. See the documentation on <literal>php-fpm.conf</literal> for details on configuration directives.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
poolConfig = mkOption {
|
|
|
|
type = types.nullOr types.lines;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Options for nextcloud's PHP pool. See the documentation on <literal>php-fpm.conf</literal> for details on configuration directives.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
database = {
|
|
|
|
|
|
|
|
createLocally = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Create the database and database user locally. Only available for
|
|
|
|
mysql database.
|
|
|
|
Note that this option will use the latest version of MariaDB which
|
|
|
|
is not officially supported by Nextcloud. As for now a workaround
|
|
|
|
is used to also support MariaDB version >= 10.6.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
config = {
|
|
|
|
dbtype = mkOption {
|
|
|
|
type = types.enum [ "sqlite" "pgsql" "mysql" ];
|
|
|
|
default = "sqlite";
|
|
|
|
description = "Database type.";
|
|
|
|
};
|
|
|
|
dbname = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "nextcloud";
|
|
|
|
description = "Database name.";
|
|
|
|
};
|
|
|
|
dbuser = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "nextcloud";
|
|
|
|
description = "Database user.";
|
|
|
|
};
|
|
|
|
dbpassFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The full path to a file that contains the database password.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
dbhost = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "localhost";
|
|
|
|
description = ''
|
|
|
|
Database host.
|
|
|
|
|
|
|
|
Note: for using Unix authentication with PostgreSQL, this should be
|
|
|
|
set to <literal>/run/postgresql</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
dbport = mkOption {
|
|
|
|
type = with types; nullOr (either int str);
|
|
|
|
default = null;
|
|
|
|
description = "Database port.";
|
|
|
|
};
|
|
|
|
dbtableprefix = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "Table prefix in Nextcloud database.";
|
|
|
|
};
|
|
|
|
adminuser = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "root";
|
|
|
|
description = "Admin username.";
|
|
|
|
};
|
|
|
|
adminpassFile = mkOption {
|
2021-10-11 16:52:03 +00:00
|
|
|
type = types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
description = ''
|
2021-02-05 17:12:51 +00:00
|
|
|
The full path to a file that contains the admin's password. Must be
|
|
|
|
readable by user <literal>nextcloud</literal>.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraTrustedDomains = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Trusted domains, from which the nextcloud installation will be
|
|
|
|
acessible. You don't need to add
|
|
|
|
<literal>services.nextcloud.hostname</literal> here.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
trustedProxies = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Trusted proxies, to provide if the nextcloud installation is being
|
|
|
|
proxied to secure against e.g. spoofing.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
overwriteProtocol = mkOption {
|
|
|
|
type = types.nullOr (types.enum [ "http" "https" ]);
|
|
|
|
default = null;
|
|
|
|
example = "https";
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
Force Nextcloud to always use HTTPS i.e. for link generation. Nextcloud
|
|
|
|
uses the currently used protocol by default, but when behind a reverse-proxy,
|
|
|
|
it may use <literal>http</literal> for everything although Nextcloud
|
|
|
|
may be served via HTTPS.
|
|
|
|
'';
|
|
|
|
};
|
2021-03-09 03:18:52 +00:00
|
|
|
|
|
|
|
defaultPhoneRegion = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
example = "DE";
|
|
|
|
description = ''
|
|
|
|
<warning>
|
|
|
|
<para>This option exists since Nextcloud 21! If older versions are used,
|
|
|
|
this will throw an eval-error!</para>
|
|
|
|
</warning>
|
|
|
|
|
|
|
|
<link xlink:href="https://www.iso.org/iso-3166-country-codes.html">ISO 3611-1</link>
|
|
|
|
country codes for automatic phone-number detection without a country code.
|
|
|
|
|
|
|
|
With e.g. <literal>DE</literal> set, the <literal>+49</literal> can be omitted for
|
|
|
|
phone-numbers.
|
|
|
|
'';
|
|
|
|
};
|
2021-10-06 13:57:05 +00:00
|
|
|
|
|
|
|
objectstore = {
|
|
|
|
s3 = {
|
|
|
|
enable = mkEnableOption ''
|
|
|
|
S3 object storage as primary storage.
|
|
|
|
|
|
|
|
This mounts a bucket on an Amazon S3 object storage or compatible
|
|
|
|
implementation into the virtual filesystem.
|
|
|
|
|
2021-10-11 16:52:03 +00:00
|
|
|
Further details about this feature can be found in the
|
|
|
|
<link xlink:href="https://docs.nextcloud.com/server/22/admin_manual/configuration_files/primary_storage.html">upstream documentation</link>.
|
2021-10-06 13:57:05 +00:00
|
|
|
'';
|
|
|
|
bucket = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "nextcloud";
|
|
|
|
description = ''
|
|
|
|
The name of the S3 bucket.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
autocreate = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Create the objectstore if it does not exist.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
key = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "EJ39ITYZEUH5BGWDRUFY";
|
|
|
|
description = ''
|
|
|
|
The access key for the S3 bucket.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
secretFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "/var/nextcloud-objectstore-s3-secret";
|
|
|
|
description = ''
|
|
|
|
The full path to a file that contains the access secret. Must be
|
|
|
|
readable by user <literal>nextcloud</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
hostname = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "example.com";
|
|
|
|
description = ''
|
|
|
|
Required for some non-Amazon implementations.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
port = mkOption {
|
|
|
|
type = types.nullOr types.port;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Required for some non-Amazon implementations.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
useSsl = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Use SSL for objectstore access.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
region = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "REGION";
|
|
|
|
description = ''
|
|
|
|
Required for some non-Amazon implementations.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
usePathStyle = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Required for some non-Amazon S3 implementations.
|
|
|
|
|
|
|
|
Ordinarily, requests will be made with
|
2021-10-11 16:52:03 +00:00
|
|
|
<literal>http://bucket.hostname.domain/</literal>, but with path style
|
2021-10-06 13:57:05 +00:00
|
|
|
enabled requests are made with
|
2021-10-11 16:52:03 +00:00
|
|
|
<literal>http://hostname.domain/bucket</literal> instead.
|
2021-10-06 13:57:05 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-04-25 03:57:28 +00:00
|
|
|
enableImagemagick = mkEnableOption ''
|
2021-10-11 16:52:03 +00:00
|
|
|
the ImageMagick module for PHP.
|
2021-03-12 07:09:13 +00:00
|
|
|
This is used by the theming app and for generating previews of certain images (e.g. SVG and HEIF).
|
|
|
|
You may want to disable it for increased security. In that case, previews will still be available
|
|
|
|
for some images (e.g. JPEG and PNG).
|
2021-10-11 16:52:03 +00:00
|
|
|
See <link xlink:href="https://github.com/nextcloud/server/issues/13099" />.
|
2021-04-25 03:57:28 +00:00
|
|
|
'' // {
|
|
|
|
default = true;
|
2021-03-12 07:09:13 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
caching = {
|
|
|
|
apcu = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to load the APCu module into PHP.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
redis = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to load the Redis module into PHP.
|
|
|
|
You still need to enable Redis in your config.php.
|
|
|
|
See https://docs.nextcloud.com/server/14/admin_manual/configuration_server/caching_configuration.html
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
memcached = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to load the Memcached module into PHP.
|
|
|
|
You still need to enable Memcached in your config.php.
|
|
|
|
See https://docs.nextcloud.com/server/14/admin_manual/configuration_server/caching_configuration.html
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
autoUpdateApps = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Run regular auto update of all apps installed from the nextcloud app store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
startAt = mkOption {
|
|
|
|
type = with types; either str (listOf str);
|
|
|
|
default = "05:00:00";
|
|
|
|
example = "Sun 14:00:00";
|
|
|
|
description = ''
|
|
|
|
When to run the update. See `systemd.services.<name>.startAt`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2020-06-15 15:56:04 +00:00
|
|
|
occ = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = occ;
|
2021-12-19 01:06:50 +00:00
|
|
|
defaultText = literalDocBook "generated script";
|
2020-06-15 15:56:04 +00:00
|
|
|
internal = true;
|
|
|
|
description = ''
|
|
|
|
The nextcloud-occ program preconfigured to target this Nextcloud instance.
|
|
|
|
'';
|
|
|
|
};
|
2022-04-27 09:35:20 +00:00
|
|
|
globalProfiles = mkEnableOption "global profiles" // {
|
|
|
|
description = ''
|
|
|
|
Makes user-profiles globally available under <literal>nextcloud.tld/u/user.name</literal>.
|
|
|
|
Even though it's enabled by default in Nextcloud, it must be explicitly enabled
|
|
|
|
here because it has the side-effect that personal information is even accessible to
|
|
|
|
unauthenticated users by default.
|
|
|
|
|
|
|
|
By default, the following properties are set to <quote>Show to everyone</quote>
|
|
|
|
if this flag is enabled:
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem><para>About</para></listitem>
|
|
|
|
<listitem><para>Full name</para></listitem>
|
|
|
|
<listitem><para>Headline</para></listitem>
|
|
|
|
<listitem><para>Organisation</para></listitem>
|
|
|
|
<listitem><para>Profile picture</para></listitem>
|
|
|
|
<listitem><para>Role</para></listitem>
|
|
|
|
<listitem><para>Twitter</para></listitem>
|
|
|
|
<listitem><para>Website</para></listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
|
|
|
|
Only has an effect in Nextcloud 23 and later.
|
|
|
|
'';
|
|
|
|
};
|
2022-01-22 01:22:15 +00:00
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
nginx = {
|
|
|
|
recommendedHttpHeaders = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Enable additional recommended HTTP response headers";
|
|
|
|
};
|
|
|
|
hstsMaxAge = mkOption {
|
|
|
|
type = types.ints.positive;
|
|
|
|
default = 15552000;
|
|
|
|
description = ''
|
|
|
|
Value for the <code>max-age</code> directive of the HTTP
|
|
|
|
<code>Strict-Transport-Security</code> header.
|
|
|
|
|
|
|
|
See section 6.1.1 of IETF RFC 6797 for detailed information on this
|
|
|
|
directive and header.
|
|
|
|
'';
|
|
|
|
};
|
2022-01-22 01:22:15 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
2021-10-28 06:52:43 +00:00
|
|
|
{ warnings = let
|
2022-05-18 14:49:53 +00:00
|
|
|
latest = 24;
|
2020-10-07 09:15:18 +00:00
|
|
|
upgradeWarning = major: nixos:
|
|
|
|
''
|
|
|
|
A legacy Nextcloud install (from before NixOS ${nixos}) may be installed.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-07 09:15:18 +00:00
|
|
|
After nextcloud${toString major} is installed successfully, you can safely upgrade
|
|
|
|
to ${toString (major + 1)}. The latest version available is nextcloud${toString latest}.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-07 09:15:18 +00:00
|
|
|
Please note that Nextcloud doesn't support upgrades across multiple major versions
|
|
|
|
(i.e. an upgrade from 16 is possible to 17, but not 16 to 18).
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-07 09:15:18 +00:00
|
|
|
The package can be upgraded by explicitly declaring the service-option
|
|
|
|
`services.nextcloud.package`.
|
|
|
|
'';
|
2021-10-04 12:37:57 +00:00
|
|
|
|
|
|
|
# FIXME(@Ma27) remove as soon as nextcloud properly supports
|
|
|
|
# mariadb >=10.6.
|
|
|
|
isUnsupportedMariadb =
|
2021-12-19 01:06:50 +00:00
|
|
|
# All currently supported Nextcloud versions are affected (https://github.com/nextcloud/server/issues/25436).
|
|
|
|
(versionOlder cfg.package.version "24")
|
2021-10-04 12:37:57 +00:00
|
|
|
# This module uses mysql
|
|
|
|
&& (cfg.config.dbtype == "mysql")
|
|
|
|
# MySQL is managed via NixOS
|
|
|
|
&& config.services.mysql.enable
|
|
|
|
# We're using MariaDB
|
|
|
|
&& (getName config.services.mysql.package) == "mariadb-server"
|
|
|
|
# MariaDB is at least 10.6 and thus not supported
|
|
|
|
&& (versionAtLeast (getVersion config.services.mysql.package) "10.6");
|
|
|
|
|
2020-10-07 09:15:18 +00:00
|
|
|
in (optional (cfg.poolConfig != null) ''
|
|
|
|
Using config.services.nextcloud.poolConfig is deprecated and will become unsupported in a future release.
|
|
|
|
Please migrate your configuration to config.services.nextcloud.poolSettings.
|
2020-06-15 15:56:04 +00:00
|
|
|
'')
|
2021-07-14 22:03:04 +00:00
|
|
|
++ (optional (versionOlder cfg.package.version "21") (upgradeWarning 20 "21.05"))
|
2021-10-04 12:37:57 +00:00
|
|
|
++ (optional (versionOlder cfg.package.version "22") (upgradeWarning 21 "21.11"))
|
2021-12-06 16:07:01 +00:00
|
|
|
++ (optional (versionOlder cfg.package.version "23") (upgradeWarning 22 "22.05"))
|
2022-05-18 14:49:53 +00:00
|
|
|
++ (optional (versionOlder cfg.package.version "24") (upgradeWarning 23 "22.05"))
|
2021-10-04 12:37:57 +00:00
|
|
|
++ (optional isUnsupportedMariadb ''
|
|
|
|
You seem to be using MariaDB at an unsupported version (i.e. at least 10.6)!
|
|
|
|
Please note that this isn't supported officially by Nextcloud. You can either
|
|
|
|
|
|
|
|
* Switch to `pkgs.mysql`
|
|
|
|
* Downgrade MariaDB to at least 10.5
|
|
|
|
* Work around Nextcloud's problems by specifying `innodb_read_only_compressed=0`
|
|
|
|
|
|
|
|
For further context, please read
|
|
|
|
https://help.nextcloud.com/t/update-to-next-cloud-21-0-2-has-get-an-error/117028/15
|
|
|
|
'');
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
services.nextcloud.package = with pkgs;
|
|
|
|
mkDefault (
|
|
|
|
if pkgs ? nextcloud
|
|
|
|
then throw ''
|
|
|
|
The `pkgs.nextcloud`-attribute has been removed. If it's supposed to be the default
|
|
|
|
nextcloud defined in an overlay, please set `services.nextcloud.package` to
|
|
|
|
`pkgs.nextcloud`.
|
|
|
|
''
|
2021-12-06 16:07:01 +00:00
|
|
|
else if versionOlder stateVersion "22.05" then nextcloud22
|
2022-05-18 14:49:53 +00:00
|
|
|
else nextcloud24
|
2020-04-24 23:36:52 +00:00
|
|
|
);
|
2021-10-04 12:37:57 +00:00
|
|
|
|
|
|
|
services.nextcloud.phpPackage =
|
2022-06-16 17:23:12 +00:00
|
|
|
if versionOlder cfg.package.version "24" then pkgs.php80
|
|
|
|
# FIXME: Use PHP 8.1 with Nextcloud 24 and higher, once issues like this one are fixed:
|
|
|
|
#
|
|
|
|
# https://github.com/nextcloud/twofactor_totp/issues/1192
|
|
|
|
#
|
|
|
|
# else if versionOlder cfg.package.version "24" then pkgs.php80
|
|
|
|
# else pkgs.php81;
|
|
|
|
else pkgs.php80;
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
{ assertions = [
|
|
|
|
{ assertion = cfg.database.createLocally -> cfg.config.dbtype == "mysql";
|
|
|
|
message = ''services.nextcloud.config.dbtype must be set to mysql if services.nextcloud.database.createLocally is set to true.'';
|
|
|
|
}
|
|
|
|
]; }
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
{ systemd.timers.nextcloud-cron = {
|
|
|
|
wantedBy = [ "timers.target" ];
|
2022-07-14 12:49:19 +00:00
|
|
|
after = [ "nextcloud-setup.service" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
timerConfig.OnBootSec = "5m";
|
2021-12-06 16:07:01 +00:00
|
|
|
timerConfig.OnUnitActiveSec = "5m";
|
2020-04-24 23:36:52 +00:00
|
|
|
timerConfig.Unit = "nextcloud-cron.service";
|
|
|
|
};
|
|
|
|
|
2022-01-27 00:19:43 +00:00
|
|
|
systemd.tmpfiles.rules = ["d ${cfg.home} 0750 nextcloud nextcloud"];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services = {
|
2020-06-15 15:56:04 +00:00
|
|
|
# When upgrading the Nextcloud package, Nextcloud can report errors such as
|
|
|
|
# "The files of the app [all apps in /var/lib/nextcloud/apps] were not replaced correctly"
|
|
|
|
# Restarting phpfpm on Nextcloud package update fixes these issues (but this is a workaround).
|
|
|
|
phpfpm-nextcloud.restartTriggers = [ cfg.package ];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
nextcloud-setup = let
|
|
|
|
c = cfg.config;
|
|
|
|
writePhpArrary = a: "[${concatMapStringsSep "," (val: ''"${toString val}"'') a}]";
|
2021-10-06 13:57:05 +00:00
|
|
|
requiresReadSecretFunction = c.dbpassFile != null || c.objectstore.s3.enable;
|
|
|
|
objectstoreConfig = let s3 = c.objectstore.s3; in optionalString s3.enable ''
|
|
|
|
'objectstore' => [
|
|
|
|
'class' => '\\OC\\Files\\ObjectStore\\S3',
|
|
|
|
'arguments' => [
|
|
|
|
'bucket' => '${s3.bucket}',
|
|
|
|
'autocreate' => ${boolToString s3.autocreate},
|
|
|
|
'key' => '${s3.key}',
|
|
|
|
'secret' => nix_read_secret('${s3.secretFile}'),
|
|
|
|
${optionalString (s3.hostname != null) "'hostname' => '${s3.hostname}',"}
|
|
|
|
${optionalString (s3.port != null) "'port' => ${toString s3.port},"}
|
|
|
|
'use_ssl' => ${boolToString s3.useSsl},
|
|
|
|
${optionalString (s3.region != null) "'region' => '${s3.region}',"}
|
|
|
|
'use_path_style' => ${boolToString s3.usePathStyle},
|
|
|
|
],
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
|
2021-10-14 00:43:12 +00:00
|
|
|
showAppStoreSetting = cfg.appstoreEnable != null || cfg.extraApps != {};
|
|
|
|
renderedAppStoreSetting =
|
|
|
|
let
|
|
|
|
x = cfg.appstoreEnable;
|
|
|
|
in
|
|
|
|
if x == null then "false"
|
|
|
|
else boolToString x;
|
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
nextcloudGreaterOrEqualThan = req: versionAtLeast cfg.package.version req;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
overrideConfig = pkgs.writeText "nextcloud-config.php" ''
|
|
|
|
<?php
|
2021-10-06 13:57:05 +00:00
|
|
|
${optionalString requiresReadSecretFunction ''
|
|
|
|
function nix_read_secret($file) {
|
2020-04-24 23:36:52 +00:00
|
|
|
if (!file_exists($file)) {
|
|
|
|
throw new \RuntimeException(sprintf(
|
2021-10-06 13:57:05 +00:00
|
|
|
"Cannot start Nextcloud, secret file %s set by NixOS doesn't seem to "
|
2020-12-25 13:55:36 +00:00
|
|
|
. "exist! Please make sure that the file exists and has appropriate "
|
|
|
|
. "permissions for user & group 'nextcloud'!",
|
2020-04-24 23:36:52 +00:00
|
|
|
$file
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
return trim(file_get_contents($file));
|
|
|
|
}
|
|
|
|
''}
|
|
|
|
$CONFIG = [
|
|
|
|
'apps_paths' => [
|
2021-10-14 00:43:12 +00:00
|
|
|
${optionalString (cfg.extraApps != { }) "[ 'path' => '${cfg.home}/nix-apps', 'url' => '/nix-apps', 'writable' => false ],"}
|
2020-04-24 23:36:52 +00:00
|
|
|
[ 'path' => '${cfg.home}/apps', 'url' => '/apps', 'writable' => false ],
|
|
|
|
[ 'path' => '${cfg.home}/store-apps', 'url' => '/store-apps', 'writable' => true ],
|
|
|
|
],
|
2021-10-14 00:43:12 +00:00
|
|
|
${optionalString (showAppStoreSetting) "'appstoreenabled' => ${renderedAppStoreSetting},"}
|
|
|
|
'datadirectory' => '${datadir}/data',
|
2020-04-24 23:36:52 +00:00
|
|
|
'skeletondirectory' => '${cfg.skeletonDirectory}',
|
|
|
|
${optionalString cfg.caching.apcu "'memcache.local' => '\\OC\\Memcache\\APCu',"}
|
|
|
|
'log_type' => 'syslog',
|
2022-05-18 14:49:53 +00:00
|
|
|
'loglevel' => '${builtins.toString cfg.logLevel}',
|
2020-04-24 23:36:52 +00:00
|
|
|
${optionalString (c.overwriteProtocol != null) "'overwriteprotocol' => '${c.overwriteProtocol}',"}
|
|
|
|
${optionalString (c.dbname != null) "'dbname' => '${c.dbname}',"}
|
|
|
|
${optionalString (c.dbhost != null) "'dbhost' => '${c.dbhost}',"}
|
|
|
|
${optionalString (c.dbport != null) "'dbport' => '${toString c.dbport}',"}
|
|
|
|
${optionalString (c.dbuser != null) "'dbuser' => '${c.dbuser}',"}
|
|
|
|
${optionalString (c.dbtableprefix != null) "'dbtableprefix' => '${toString c.dbtableprefix}',"}
|
2021-10-06 13:57:05 +00:00
|
|
|
${optionalString (c.dbpassFile != null) "'dbpassword' => nix_read_secret('${c.dbpassFile}'),"}
|
2020-04-24 23:36:52 +00:00
|
|
|
'dbtype' => '${c.dbtype}',
|
|
|
|
'trusted_domains' => ${writePhpArrary ([ cfg.hostName ] ++ c.extraTrustedDomains)},
|
|
|
|
'trusted_proxies' => ${writePhpArrary (c.trustedProxies)},
|
2021-03-09 03:18:52 +00:00
|
|
|
${optionalString (c.defaultPhoneRegion != null) "'default_phone_region' => '${c.defaultPhoneRegion}',"}
|
2022-06-16 17:23:12 +00:00
|
|
|
${optionalString (nextcloudGreaterOrEqualThan "23") "'profile.enabled' => ${boolToString cfg.globalProfiles},"}
|
2021-10-06 13:57:05 +00:00
|
|
|
${objectstoreConfig}
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
'';
|
|
|
|
occInstallCmd = let
|
2021-10-11 16:52:03 +00:00
|
|
|
mkExport = { arg, value }: "export ${arg}=${value}";
|
|
|
|
dbpass = {
|
|
|
|
arg = "DBPASS";
|
|
|
|
value = if c.dbpassFile != null
|
|
|
|
then ''"$(<"${toString c.dbpassFile}")"''
|
|
|
|
else ''""'';
|
|
|
|
};
|
|
|
|
adminpass = {
|
|
|
|
arg = "ADMINPASS";
|
|
|
|
value = ''"$(<"${toString c.adminpassFile}")"'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
installFlags = concatStringsSep " \\\n "
|
|
|
|
(mapAttrsToList (k: v: "${k} ${toString v}") {
|
|
|
|
"--database" = ''"${c.dbtype}"'';
|
|
|
|
# The following attributes are optional depending on the type of
|
|
|
|
# database. Those that evaluate to null on the left hand side
|
|
|
|
# will be omitted.
|
|
|
|
${if c.dbname != null then "--database-name" else null} = ''"${c.dbname}"'';
|
|
|
|
${if c.dbhost != null then "--database-host" else null} = ''"${c.dbhost}"'';
|
|
|
|
${if c.dbport != null then "--database-port" else null} = ''"${toString c.dbport}"'';
|
|
|
|
${if c.dbuser != null then "--database-user" else null} = ''"${c.dbuser}"'';
|
2021-10-11 16:52:03 +00:00
|
|
|
"--database-pass" = "\$${dbpass.arg}";
|
2020-04-24 23:36:52 +00:00
|
|
|
"--admin-user" = ''"${c.adminuser}"'';
|
2021-10-11 16:52:03 +00:00
|
|
|
"--admin-pass" = "\$${adminpass.arg}";
|
2021-10-14 00:43:12 +00:00
|
|
|
"--data-dir" = ''"${datadir}/data"'';
|
2020-04-24 23:36:52 +00:00
|
|
|
});
|
|
|
|
in ''
|
2021-10-11 16:52:03 +00:00
|
|
|
${mkExport dbpass}
|
|
|
|
${mkExport adminpass}
|
2020-04-24 23:36:52 +00:00
|
|
|
${occ}/bin/nextcloud-occ maintenance:install \
|
|
|
|
${installFlags}
|
|
|
|
'';
|
|
|
|
occSetTrustedDomainsCmd = concatStringsSep "\n" (imap0
|
|
|
|
(i: v: ''
|
|
|
|
${occ}/bin/nextcloud-occ config:system:set trusted_domains \
|
|
|
|
${toString i} --value="${toString v}"
|
|
|
|
'') ([ cfg.hostName ] ++ cfg.config.extraTrustedDomains));
|
|
|
|
|
|
|
|
in {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
before = [ "phpfpm-nextcloud.service" ];
|
|
|
|
path = [ occ ];
|
|
|
|
script = ''
|
2021-02-13 14:23:35 +00:00
|
|
|
${optionalString (c.dbpassFile != null) ''
|
|
|
|
if [ ! -r "${c.dbpassFile}" ]; then
|
|
|
|
echo "dbpassFile ${c.dbpassFile} is not readable by nextcloud:nextcloud! Aborting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "$(<${c.dbpassFile})" ]; then
|
|
|
|
echo "dbpassFile ${c.dbpassFile} is empty!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
''}
|
2021-10-11 16:52:03 +00:00
|
|
|
if [ ! -r "${c.adminpassFile}" ]; then
|
|
|
|
echo "adminpassFile ${c.adminpassFile} is not readable by nextcloud:nextcloud! Aborting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "$(<${c.adminpassFile})" ]; then
|
|
|
|
echo "adminpassFile ${c.adminpassFile} is empty!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-02-13 14:23:35 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
ln -sf ${cfg.package}/apps ${cfg.home}/
|
|
|
|
|
2021-10-14 00:43:12 +00:00
|
|
|
# Install extra apps
|
|
|
|
ln -sfT \
|
|
|
|
${pkgs.linkFarm "nix-apps"
|
|
|
|
(mapAttrsToList (name: path: { inherit name path; }) cfg.extraApps)} \
|
|
|
|
${cfg.home}/nix-apps
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
# create nextcloud directories.
|
|
|
|
# if the directories exist already with wrong permissions, we fix that
|
2021-10-14 00:43:12 +00:00
|
|
|
for dir in ${datadir}/config ${datadir}/data ${cfg.home}/store-apps ${cfg.home}/nix-apps; do
|
2020-08-20 17:08:02 +00:00
|
|
|
if [ ! -e $dir ]; then
|
|
|
|
install -o nextcloud -g nextcloud -d $dir
|
|
|
|
elif [ $(stat -c "%G" $dir) != "nextcloud" ]; then
|
|
|
|
chgrp -R nextcloud $dir
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2021-10-14 00:43:12 +00:00
|
|
|
ln -sf ${overrideConfig} ${datadir}/config/override.config.php
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# Do not install if already installed
|
2021-10-14 00:43:12 +00:00
|
|
|
if [[ ! -e ${datadir}/config/config.php ]]; then
|
2020-04-24 23:36:52 +00:00
|
|
|
${occInstallCmd}
|
|
|
|
fi
|
|
|
|
|
|
|
|
${occ}/bin/nextcloud-occ upgrade
|
|
|
|
|
|
|
|
${occ}/bin/nextcloud-occ config:system:delete trusted_domains
|
2021-10-14 00:43:12 +00:00
|
|
|
|
|
|
|
${optionalString (cfg.extraAppsEnable && cfg.extraApps != { }) ''
|
2022-06-16 17:23:12 +00:00
|
|
|
# Try to enable apps
|
2021-10-14 00:43:12 +00:00
|
|
|
${occ}/bin/nextcloud-occ app:enable ${concatStringsSep " " (attrNames cfg.extraApps)}
|
|
|
|
''}
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
${occSetTrustedDomainsCmd}
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
2020-08-20 17:08:02 +00:00
|
|
|
serviceConfig.User = "nextcloud";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
nextcloud-cron = {
|
2022-07-14 12:49:19 +00:00
|
|
|
after = [ "nextcloud-setup.service" ];
|
2021-10-14 00:43:12 +00:00
|
|
|
environment.NEXTCLOUD_CONFIG_DIR = "${datadir}/config";
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.User = "nextcloud";
|
|
|
|
serviceConfig.ExecStart = "${phpPackage}/bin/php -f ${cfg.package}/cron.php";
|
|
|
|
};
|
|
|
|
nextcloud-update-plugins = mkIf cfg.autoUpdateApps.enable {
|
2022-07-14 12:49:19 +00:00
|
|
|
after = [ "nextcloud-setup.service" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.ExecStart = "${occ}/bin/nextcloud-occ app:update --all";
|
|
|
|
serviceConfig.User = "nextcloud";
|
|
|
|
startAt = cfg.autoUpdateApps.startAt;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.phpfpm = {
|
|
|
|
pools.nextcloud = {
|
|
|
|
user = "nextcloud";
|
2020-08-20 17:08:02 +00:00
|
|
|
group = "nextcloud";
|
2020-04-24 23:36:52 +00:00
|
|
|
phpPackage = phpPackage;
|
|
|
|
phpEnv = {
|
2021-10-14 00:43:12 +00:00
|
|
|
NEXTCLOUD_CONFIG_DIR = "${datadir}/config";
|
2020-04-24 23:36:52 +00:00
|
|
|
PATH = "/run/wrappers/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/usr/bin:/bin";
|
|
|
|
};
|
|
|
|
settings = mapAttrs (name: mkDefault) {
|
2020-08-20 17:08:02 +00:00
|
|
|
"listen.owner" = config.services.nginx.user;
|
|
|
|
"listen.group" = config.services.nginx.group;
|
2020-04-24 23:36:52 +00:00
|
|
|
} // cfg.poolSettings;
|
|
|
|
extraConfig = cfg.poolConfig;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
users.users.nextcloud = {
|
2020-04-24 23:36:52 +00:00
|
|
|
home = "${cfg.home}";
|
2020-08-20 17:08:02 +00:00
|
|
|
group = "nextcloud";
|
2021-04-15 00:37:46 +00:00
|
|
|
isSystemUser = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2020-08-20 17:08:02 +00:00
|
|
|
users.groups.nextcloud.members = [ "nextcloud" config.services.nginx.user ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ occ ];
|
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
services.mysql = lib.mkIf cfg.database.createLocally {
|
|
|
|
enable = true;
|
|
|
|
package = lib.mkDefault pkgs.mariadb;
|
|
|
|
ensureDatabases = [ cfg.config.dbname ];
|
|
|
|
ensureUsers = [{
|
|
|
|
name = cfg.config.dbuser;
|
|
|
|
ensurePermissions = { "${cfg.config.dbname}.*" = "ALL PRIVILEGES"; };
|
|
|
|
}];
|
|
|
|
# FIXME(@Ma27) Nextcloud isn't compatible with mariadb 10.6,
|
|
|
|
# this is a workaround.
|
|
|
|
# See https://help.nextcloud.com/t/update-to-next-cloud-21-0-2-has-get-an-error/117028/22
|
2022-05-18 14:49:53 +00:00
|
|
|
settings = mkIf (versionOlder cfg.package.version "24") {
|
2022-04-27 09:35:20 +00:00
|
|
|
mysqld = {
|
|
|
|
innodb_read_only_compressed = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
initialScript = pkgs.writeText "mysql-init" ''
|
|
|
|
CREATE USER '${cfg.config.dbname}'@'localhost' IDENTIFIED BY '${builtins.readFile( cfg.config.dbpassFile )}';
|
|
|
|
CREATE DATABASE IF NOT EXISTS ${cfg.config.dbname};
|
|
|
|
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER,
|
|
|
|
CREATE TEMPORARY TABLES ON ${cfg.config.dbname}.* TO '${cfg.config.dbuser}'@'localhost'
|
|
|
|
IDENTIFIED BY '${builtins.readFile( cfg.config.dbpassFile )}';
|
|
|
|
FLUSH privileges;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
services.nginx.enable = mkDefault true;
|
2020-10-07 09:15:18 +00:00
|
|
|
|
2021-07-14 22:03:04 +00:00
|
|
|
services.nginx.virtualHosts.${cfg.hostName} = {
|
2020-08-20 17:08:02 +00:00
|
|
|
root = cfg.package;
|
|
|
|
locations = {
|
|
|
|
"= /robots.txt" = {
|
|
|
|
priority = 100;
|
2020-04-24 23:36:52 +00:00
|
|
|
extraConfig = ''
|
2020-08-20 17:08:02 +00:00
|
|
|
allow all;
|
|
|
|
access_log off;
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-03-09 03:18:52 +00:00
|
|
|
"= /" = {
|
|
|
|
priority = 100;
|
|
|
|
extraConfig = ''
|
|
|
|
if ( $http_user_agent ~ ^DavClnt ) {
|
|
|
|
return 302 /remote.php/webdav/$is_args$args;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2020-08-20 17:08:02 +00:00
|
|
|
"/" = {
|
|
|
|
priority = 900;
|
2020-11-03 02:18:15 +00:00
|
|
|
extraConfig = "rewrite ^ /index.php;";
|
2020-08-20 17:08:02 +00:00
|
|
|
};
|
|
|
|
"~ ^/store-apps" = {
|
|
|
|
priority = 201;
|
|
|
|
extraConfig = "root ${cfg.home};";
|
|
|
|
};
|
2021-10-14 00:43:12 +00:00
|
|
|
"~ ^/nix-apps" = {
|
|
|
|
priority = 201;
|
|
|
|
extraConfig = "root ${cfg.home};";
|
|
|
|
};
|
2020-08-20 17:08:02 +00:00
|
|
|
"^~ /.well-known" = {
|
|
|
|
priority = 210;
|
|
|
|
extraConfig = ''
|
2021-02-17 17:02:09 +00:00
|
|
|
absolute_redirect off;
|
2020-08-20 17:08:02 +00:00
|
|
|
location = /.well-known/carddav {
|
2021-02-16 17:04:54 +00:00
|
|
|
return 301 /remote.php/dav;
|
2020-08-20 17:08:02 +00:00
|
|
|
}
|
|
|
|
location = /.well-known/caldav {
|
2021-02-16 17:04:54 +00:00
|
|
|
return 301 /remote.php/dav;
|
2020-08-20 17:08:02 +00:00
|
|
|
}
|
2021-03-09 03:18:52 +00:00
|
|
|
location ~ ^/\.well-known/(?!acme-challenge|pki-validation) {
|
|
|
|
return 301 /index.php$request_uri;
|
|
|
|
}
|
2020-08-20 17:08:02 +00:00
|
|
|
try_files $uri $uri/ =404;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
"~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)".extraConfig = ''
|
|
|
|
return 404;
|
|
|
|
'';
|
2021-02-16 17:04:54 +00:00
|
|
|
"~ ^/(?:\\.(?!well-known)|autotest|occ|issue|indie|db_|console)".extraConfig = ''
|
2020-08-20 17:08:02 +00:00
|
|
|
return 404;
|
|
|
|
'';
|
2020-11-03 02:18:15 +00:00
|
|
|
"~ ^\\/(?:index|remote|public|cron|core\\/ajax\\/update|status|ocs\\/v[12]|updater\\/.+|oc[ms]-provider\\/.+|.+\\/richdocumentscode\\/proxy)\\.php(?:$|\\/)" = {
|
2020-08-20 17:08:02 +00:00
|
|
|
priority = 500;
|
|
|
|
extraConfig = ''
|
|
|
|
include ${config.services.nginx.package}/conf/fastcgi.conf;
|
|
|
|
fastcgi_split_path_info ^(.+?\.php)(\\/.*)$;
|
|
|
|
set $path_info $fastcgi_path_info;
|
|
|
|
try_files $fastcgi_script_name =404;
|
|
|
|
fastcgi_param PATH_INFO $path_info;
|
|
|
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
|
|
|
fastcgi_param HTTPS ${if cfg.https then "on" else "off"};
|
|
|
|
fastcgi_param modHeadersAvailable true;
|
|
|
|
fastcgi_param front_controller_active true;
|
|
|
|
fastcgi_pass unix:${fpm.socket};
|
|
|
|
fastcgi_intercept_errors on;
|
|
|
|
fastcgi_request_buffering off;
|
|
|
|
fastcgi_read_timeout 120s;
|
|
|
|
'';
|
|
|
|
};
|
2020-10-11 12:50:04 +00:00
|
|
|
"~ \\.(?:css|js|woff2?|svg|gif|map)$".extraConfig = ''
|
2020-08-20 17:08:02 +00:00
|
|
|
try_files $uri /index.php$request_uri;
|
|
|
|
expires 6M;
|
|
|
|
access_log off;
|
|
|
|
'';
|
|
|
|
"~ ^\\/(?:updater|ocs-provider|ocm-provider)(?:$|\\/)".extraConfig = ''
|
|
|
|
try_files $uri/ =404;
|
|
|
|
index index.php;
|
|
|
|
'';
|
2020-10-11 12:50:04 +00:00
|
|
|
"~ \\.(?:png|html|ttf|ico|jpg|jpeg|bcmap|mp4|webm)$".extraConfig = ''
|
|
|
|
try_files $uri /index.php$request_uri;
|
|
|
|
access_log off;
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2020-08-20 17:08:02 +00:00
|
|
|
extraConfig = ''
|
|
|
|
index index.php index.html /index.php$request_uri;
|
2022-01-22 01:22:15 +00:00
|
|
|
${optionalString (cfg.nginx.recommendedHttpHeaders) ''
|
|
|
|
add_header X-Content-Type-Options nosniff;
|
|
|
|
add_header X-XSS-Protection "1; mode=block";
|
|
|
|
add_header X-Robots-Tag none;
|
|
|
|
add_header X-Download-Options noopen;
|
|
|
|
add_header X-Permitted-Cross-Domain-Policies none;
|
|
|
|
add_header X-Frame-Options sameorigin;
|
|
|
|
add_header Referrer-Policy no-referrer;
|
2022-05-18 14:49:53 +00:00
|
|
|
''}
|
|
|
|
${optionalString (cfg.https) ''
|
|
|
|
add_header Strict-Transport-Security "max-age=${toString cfg.nginx.hstsMaxAge}; includeSubDomains" always;
|
2022-01-22 01:22:15 +00:00
|
|
|
''}
|
2020-08-20 17:08:02 +00:00
|
|
|
client_max_body_size ${cfg.maxUploadSize};
|
|
|
|
fastcgi_buffers 64 4K;
|
|
|
|
fastcgi_hide_header X-Powered-By;
|
|
|
|
gzip on;
|
|
|
|
gzip_vary on;
|
|
|
|
gzip_comp_level 4;
|
|
|
|
gzip_min_length 256;
|
|
|
|
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
|
|
|
|
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
|
|
|
|
|
|
|
|
${optionalString cfg.webfinger ''
|
|
|
|
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
|
|
|
|
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
|
|
|
|
''}
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2020-08-20 17:08:02 +00:00
|
|
|
}
|
2020-04-24 23:36:52 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
meta.doc = ./nextcloud.xml;
|
|
|
|
}
|