1 { lib, pkgs, config, ... }:
3 nextcloud = pkgs.webapps.nextcloud.withApps (a: [
4 a.apporder a.audioplayer a.bookmarks a.calendar a.carnet a.contacts
5 a.cookbook a.deck a.extract a.files_markdown a.files_readmemd
6 a.flowupload a.gpxedit a.gpxpod a.keeweb a.maps a.metadata a.music
7 a.notes a.ocsms a.passman a.polls a.spreed a.tasks
9 env = config.myEnv.tools.nextcloud;
10 varDir = "/var/lib/nextcloud";
11 cfg = config.myServices.websites.tools.cloud;
13 basedir = builtins.concatStringsSep ":" ([ nextcloud varDir ] ++ nextcloud.apps);
15 "listen.owner" = "wwwrun";
16 "listen.group" = "wwwrun";
18 "pm.max_children" = "60";
19 "pm.process_idle_timeout" = "60";
21 "php_admin_value[output_buffering]" = "0";
22 "php_admin_value[max_execution_time]" = "1800";
23 "php_admin_value[zend_extension]" = "opcache";
24 #already enabled by default?
25 #"php_value[opcache.enable]" = "1";
26 "php_value[opcache.enable_cli]" = "1";
27 "php_value[opcache.interned_strings_buffer]" = "8";
28 "php_value[opcache.max_accelerated_files]" = "10000";
29 "php_value[opcache.memory_consumption]" = "128";
30 "php_value[opcache.save_comments]" = "1";
31 "php_value[opcache.revalidate_freq]" = "1";
32 "php_admin_value[memory_limit]" = "512M";
34 "php_admin_value[open_basedir]" = "/run/wrappers/bin/sendmail:${basedir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp";
35 "php_admin_value[session.save_path]" = "${varDir}/phpSessions";
39 options.myServices.websites.tools.cloud = {
40 enable = lib.mkEnableOption "enable cloud website";
43 config = lib.mkIf cfg.enable {
44 services.websites.env.tools.modules = [ "proxy_fcgi" ];
46 services.websites.env.tools.vhostConfs.cloud = {
49 hosts = ["cloud.immae.eu" ];
53 SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
54 <Directory ${nextcloud}>
56 DirectoryIndex index.php
57 Options FollowSymlinks
61 <IfModule mod_headers.c>
62 Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
66 SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud.socket}|fcgi://localhost"
74 secrets.keys."webapps/tools-nextcloud" = {
78 # This file is not actually included, see activationScript below
81 include('${nextcloud}/version.php');
83 // FIXME: change this value when nextcloud starts getting slow
84 'instanceid' => '${env.instance_id}',
85 'datadirectory' => '/var/lib/nextcloud/',
86 'passwordsalt' => '${env.password_salt}',
89 'version' => implode($OC_Version, '.'),
90 'dbname' => '${env.postgresql.database}',
91 'dbhost' => '${env.postgresql.socket}',
92 'dbtableprefix' => 'oc_',
93 'dbuser' => '${env.postgresql.user}',
94 'dbpassword' => '${env.postgresql.password}',
96 'maxZipInputSize' => 0,
97 'allowZipDownload' => true,
100 'maintenance' => false,
103 0 => 'cloud.immae.eu',
105 'secret' => '${env.secret}',
106 'appstoreenabled' => false,
107 'appstore.experimental.enabled' => true,
109 'trashbin_retention_obligation' => 'auto',
110 'htaccess.RewriteBase' => '/',
111 'mail_smtpmode' => 'sendmail',
112 'mail_smtphost' => '127.0.0.1',
113 'mail_smtpname' => ''',
114 'mail_smtppassword' => ''',
115 'mail_from_address' => 'nextcloud',
116 'mail_smtpauth' => false,
117 'mail_domain' => 'tools.immae.eu',
118 'memcache.local' => '\\OC\\Memcache\\APCu',
119 'memcache.locking' => '\\OC\\Memcache\\Redis',
120 'filelocking.enabled' => true,
123 'host' => '${env.redis.socket}',
125 'dbindex' => ${env.redis.db},
127 'overwrite.cli.url' => 'https://cloud.immae.eu',
128 'ldapIgnoreNamingRules' => false,
129 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
130 'has_rebuilt_cache' => true,
134 users.users.root.packages = let
135 occ = pkgs.writeScriptBin "nextcloud-occ" ''
136 #! ${pkgs.stdenv.shell}
138 NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \
140 sudo -E -u wwwrun ${pkgs.php74}/bin/php \
141 -c ${pkgs.php74}/etc/php.ini \
146 system.activationScripts.nextcloud = {
147 deps = [ "secrets" ];
149 confs = lib.attrsets.mapAttrs (n: v: pkgs.writeText "${n}.json" (builtins.toJSON v)) nextcloud.otherConfig;
152 install -m 0755 -o wwwrun -g wwwrun -d ${varDir}
153 install -m 0750 -o wwwrun -g wwwrun -d ${varDir}/phpSessions
154 ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v:
155 "install -D -m 0644 -o wwwrun -g wwwrun -T ${v} ${varDir}/config/${n}.json"
157 #install -D -m 0600 -o wwwrun -g wwwrun -T ${config.secrets.fullPaths."webapps/tools-nextcloud"} ${varDir}/config/config.php
161 services.phpfpm.pools.nextcloud = {
164 settings = phpFpm.pool;
165 phpPackage = pkgs.php74.withExtensions({ enabled, all }: enabled ++ [ all.redis all.apcu all.opcache ]);
171 script = pkgs.writeScriptBin "nextcloud-cron" ''
172 #! ${pkgs.stdenv.shell}
173 export LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive
174 export PATH=/run/wrappers/bin:$PATH
175 ${pkgs.php74}/bin/php -d memory_limit=2048M -f ${nextcloud}/cron.php
179 */15 * * * * wwwrun ${script}/bin/nextcloud-cron