1 { lib, pkgs, config, ... }:
3 phpPackage = (pkgs.php74.withExtensions({ enabled, all }: enabled ++ [ all.redis all.apcu all.opcache all.imagick ])).override { extraConfig = ''
7 nextcloud = pkgs.webapps.nextcloud_22.withApps (a: [
8 a.apporder a.audioplayer a.bookmarks a.calendar a.carnet a.contacts
9 a.cookbook a.deck a.extract a.files_markdown a.files_readmemd a.files_mindmap
10 a.flowupload a.gpxedit a.gpxpod a.keeweb a.maps a.metadata a.music
11 a.notes a.passman a.polls a.spreed a.tasks
13 env = config.myEnv.tools.nextcloud;
14 varDir = "/var/lib/nextcloud";
15 cfg = config.myServices.websites.tools.cloud;
17 basedir = builtins.concatStringsSep ":" ([ nextcloud varDir ] ++ nextcloud.apps);
19 "listen.owner" = "wwwrun";
20 "listen.group" = "wwwrun";
22 "pm.max_children" = "60";
23 "pm.start_servers" = "2";
24 "pm.min_spare_servers" = "2";
25 "pm.max_spare_servers" = "3";
26 "pm.process_idle_timeout" = "60";
28 "php_admin_value[output_buffering]" = "0";
29 "php_admin_value[max_execution_time]" = "1800";
30 "php_admin_value[zend_extension]" = "opcache";
31 #already enabled by default?
32 #"php_value[opcache.enable]" = "1";
33 "php_value[opcache.enable_cli]" = "1";
34 "php_value[opcache.interned_strings_buffer]" = "8";
35 "php_value[opcache.max_accelerated_files]" = "10000";
36 "php_value[opcache.memory_consumption]" = "128";
37 "php_value[opcache.save_comments]" = "1";
38 "php_value[opcache.revalidate_freq]" = "1";
39 "php_admin_value[memory_limit]" = "512M";
41 "php_admin_value[open_basedir]" = "/run/wrappers/bin/sendmail:${basedir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp";
42 "php_admin_value[session.save_path]" = "${varDir}/phpSessions";
46 options.myServices.websites.tools.cloud = {
47 enable = lib.mkEnableOption "enable cloud website";
50 config = lib.mkIf cfg.enable {
51 myServices.chatonsProperties.hostings.nextcloud = {
52 file.datetime = "2022-08-21T19:50:00";
55 description = "The self-hosted productivity platform that keeps you in control";
56 website = "https://cloud.immae.eu/";
57 logo = "https://cloud.immae.eu/core/img/favicon.ico";
60 status.description = "OK";
61 registration.load = "OPEN";
62 install.type = "PACKAGE";
65 myServices.chatonsProperties.services.nextcloud = {
66 file.datetime = "2022-08-21T19:50:00";
69 description = "The self-hosted productivity platform that keeps you in control";
70 website = "https://cloud.immae.eu/";
71 logo = "https://cloud.immae.eu/core/img/favicon.ico";
73 status.description = "OK";
74 registration."" = ["MEMBER" "CLIENT"];
75 registration.load = "OPEN";
76 install.type = "PACKAGE";
77 guide.user = "https://www.immae.eu/docs/nextcloud.html";
81 website = "https://nextcloud.com/";
82 license.url = "https://github.com/nextcloud/server/blob/master/COPYING";
83 license.name = "GNU Affero General Public License v3.0";
84 version = nextcloud.version;
85 source.url = "https://github.com/nextcloud/server";
86 modules = map (a: a.appName) nextcloud.apps;
89 services.websites.env.tools.modules = [ "proxy_fcgi" ];
91 services.websites.env.tools.vhostConfs.cloud = {
94 hosts = ["cloud.immae.eu" ];
98 SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
99 <Directory ${nextcloud}>
101 DirectoryIndex index.php
102 Options FollowSymlinks
106 <IfModule mod_headers.c>
107 Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
109 <FilesMatch "\.php$">
111 SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud.socket}|fcgi://localhost"
119 secrets.keys."webapps/tools-nextcloud" = {
122 permissions = "0600";
123 # This file is not actually included, see activationScript below
126 include('${nextcloud}/version.php');
128 // FIXME: change this value when nextcloud starts getting slow
129 'instanceid' => '${env.instance_id}',
130 'datadirectory' => '/var/lib/nextcloud/',
131 'passwordsalt' => '${env.password_salt}',
134 'version' => implode($OC_Version, '.'),
135 'dbname' => '${env.postgresql.database}',
136 'dbhost' => '${env.postgresql.socket}',
137 'dbtableprefix' => 'oc_',
138 'dbuser' => '${env.postgresql.user}',
139 'dbpassword' => '${env.postgresql.password}',
141 'maxZipInputSize' => 0,
142 'allowZipDownload' => true,
145 'remember_login_cookie_lifetime' => 60*60*24*30,
146 'session_keepalive' => true,
147 'session_lifefime' => 60*60*24*30,
148 'maintenance' => false,
151 0 => 'cloud.immae.eu',
153 'secret' => '${env.secret}',
154 'appstoreenabled' => false,
155 'appstore.experimental.enabled' => true,
157 'trashbin_retention_obligation' => 'auto',
158 'htaccess.RewriteBase' => '/',
159 'mail_smtpmode' => 'sendmail',
160 'mail_smtphost' => '127.0.0.1',
161 'mail_smtpname' => ''',
162 'mail_smtppassword' => ''',
163 'mail_from_address' => 'nextcloud',
164 'mail_smtpauth' => false,
165 'mail_domain' => 'tools.immae.eu',
166 'memcache.local' => '\\OC\\Memcache\\APCu',
167 'memcache.locking' => '\\OC\\Memcache\\Redis',
168 'filelocking.enabled' => true,
171 'host' => '${env.redis.socket}',
173 'dbindex' => ${env.redis.db},
175 'overwrite.cli.url' => 'https://cloud.immae.eu',
176 'ldapIgnoreNamingRules' => false,
177 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
178 'has_rebuilt_cache' => true,
182 users.users.root.packages = let
183 occ = pkgs.writeScriptBin "nextcloud-occ" ''
184 #! ${pkgs.stdenv.shell}
186 NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \
188 sudo -E -u wwwrun ${phpPackage}/bin/php \
189 -c ${phpPackage}/etc/php.ini \
194 system.activationScripts.nextcloud = {
195 deps = [ "secrets" ];
197 confs = lib.attrsets.mapAttrs (n: v: pkgs.writeText "${n}.json" (builtins.toJSON v)) nextcloud.otherConfig;
200 install -m 0755 -o wwwrun -g wwwrun -d ${varDir}
201 install -m 0750 -o wwwrun -g wwwrun -d ${varDir}/phpSessions
202 ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v:
203 "install -D -m 0644 -o wwwrun -g wwwrun -T ${v} ${varDir}/config/${n}.json"
205 #install -D -m 0600 -o wwwrun -g wwwrun -T ${config.secrets.fullPaths."webapps/tools-nextcloud"} ${varDir}/config/config.php
209 services.phpfpm.pools.nextcloud = {
212 settings = phpFpm.pool;
219 script = pkgs.writeScriptBin "nextcloud-cron" ''
220 #! ${pkgs.stdenv.shell}
221 export LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive
222 export PATH=/run/wrappers/bin:$PATH
223 ${phpPackage}/bin/php -d memory_limit=2048M -f ${nextcloud}/cron.php
227 */15 * * * * wwwrun ${script}/bin/nextcloud-cron