]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/websites/tools/cloud/default.nix
Add chatons infos
[perso/Immae/Config/Nix.git] / modules / private / websites / tools / cloud / default.nix
CommitLineData
ab8f306d 1{ lib, pkgs, config, ... }:
10889174 2let
792ccef2
IB
3 phpPackage = (pkgs.php74.withExtensions({ enabled, all }: enabled ++ [ all.redis all.apcu all.opcache all.imagick ])).override { extraConfig = ''
4 apc.enable_cli = 1
5 '';
6 };
7 nextcloud = pkgs.webapps.nextcloud_22.withApps (a: [
65b715d7 8 a.apporder a.audioplayer a.bookmarks a.calendar a.carnet a.contacts
5a412244 9 a.cookbook a.deck a.extract a.files_markdown a.files_readmemd a.files_mindmap
65b715d7 10 a.flowupload a.gpxedit a.gpxpod a.keeweb a.maps a.metadata a.music
792ccef2 11 a.notes a.passman a.polls a.spreed a.tasks
65b715d7 12 ]);
ab8f306d 13 env = config.myEnv.tools.nextcloud;
0ede7366 14 varDir = "/var/lib/nextcloud";
4288c2f2 15 cfg = config.myServices.websites.tools.cloud;
0ede7366 16 phpFpm = rec {
65b715d7 17 basedir = builtins.concatStringsSep ":" ([ nextcloud varDir ] ++ nextcloud.apps);
5400b9b6
IB
18 pool = {
19 "listen.owner" = "wwwrun";
20 "listen.group" = "wwwrun";
792ccef2 21 "pm" = "dynamic";
5400b9b6 22 "pm.max_children" = "60";
792ccef2
IB
23 "pm.start_servers" = "2";
24 "pm.min_spare_servers" = "2";
25 "pm.max_spare_servers" = "3";
5400b9b6 26 "pm.process_idle_timeout" = "60";
0ede7366 27
5400b9b6
IB
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";
10889174 40
5400b9b6
IB
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";
43 };
0ede7366 44 };
10889174 45in {
4288c2f2 46 options.myServices.websites.tools.cloud = {
10889174
IB
47 enable = lib.mkEnableOption "enable cloud website";
48 };
49
50 config = lib.mkIf cfg.enable {
120bcf4d
IB
51 myServices.chatonsProperties.hostings.nextcloud = {
52 file.datetime = "2022-08-21T19:50:00";
53 hosting = {
54 name = "Nextcloud";
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";
58 type = "INSTANCE";
59 status.level = "OK";
60 status.description = "OK";
61 registration.load = "OPEN";
62 install.type = "PACKAGE";
63 };
64 };
65 myServices.chatonsProperties.services.nextcloud = {
66 file.datetime = "2022-08-21T19:50:00";
67 service = {
68 name = "Nextcloud";
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";
72 status.level = "OK";
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";
78 };
79 software = {
80 name = "Nextcloud";
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;
87 };
88 };
29f8cb85 89 services.websites.env.tools.modules = [ "proxy_fcgi" ];
10889174 90
29f8cb85 91 services.websites.env.tools.vhostConfs.cloud = {
10889174 92 certName = "eldiron";
7df420c2 93 addToCerts = true;
10889174 94 hosts = ["cloud.immae.eu" ];
750fe5a4 95 root = nextcloud;
10889174 96 extraConfig = [
0ede7366
IB
97 ''
98 SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
750fe5a4 99 <Directory ${nextcloud}>
0ede7366
IB
100 AcceptPathInfo On
101 DirectoryIndex index.php
102 Options FollowSymlinks
103 Require all granted
104 AllowOverride all
105
106 <IfModule mod_headers.c>
107 Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
108 </IfModule>
109 <FilesMatch "\.php$">
110 CGIPassAuth on
5400b9b6 111 SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud.socket}|fcgi://localhost"
0ede7366
IB
112 </FilesMatch>
113
114 </Directory>
115 ''
10889174
IB
116 ];
117 };
118
4c4652aa 119 secrets.keys."webapps/tools-nextcloud" = {
0ede7366
IB
120 user = "wwwrun";
121 group = "wwwrun";
122 permissions = "0600";
c4216ddb 123 # This file is not actually included, see activationScript below
0ede7366
IB
124 text = ''
125 <?php
c4216ddb 126 include('${nextcloud}/version.php');
0ede7366
IB
127 $CONFIG = array (
128 // FIXME: change this value when nextcloud starts getting slow
50abe6fc 129 'instanceid' => '${env.instance_id}',
0ede7366
IB
130 'datadirectory' => '/var/lib/nextcloud/',
131 'passwordsalt' => '${env.password_salt}',
132 'debug' => false,
133 'dbtype' => 'pgsql',
c4216ddb 134 'version' => implode($OC_Version, '.'),
0ede7366
IB
135 'dbname' => '${env.postgresql.database}',
136 'dbhost' => '${env.postgresql.socket}',
137 'dbtableprefix' => 'oc_',
138 'dbuser' => '${env.postgresql.user}',
139 'dbpassword' => '${env.postgresql.password}',
140 'installed' => true,
141 'maxZipInputSize' => 0,
142 'allowZipDownload' => true,
143 'forcessl' => true,
144 'theme' => ${"''"},
792ccef2
IB
145 'remember_login_cookie_lifetime' => 60*60*24*30,
146 'session_keepalive' => true,
147 'session_lifefime' => 60*60*24*30,
0ede7366
IB
148 'maintenance' => false,
149 'trusted_domains' =>
150 array (
151 0 => 'cloud.immae.eu',
152 ),
153 'secret' => '${env.secret}',
154 'appstoreenabled' => false,
155 'appstore.experimental.enabled' => true,
156 'loglevel' => 2,
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,
169 'redis' =>
170 array (
171 'host' => '${env.redis.socket}',
172 'port' => 0,
ab8f306d 173 'dbindex' => ${env.redis.db},
0ede7366
IB
174 ),
175 'overwrite.cli.url' => 'https://cloud.immae.eu',
176 'ldapIgnoreNamingRules' => false,
177 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
3a1461cf 178 'has_rebuilt_cache' => true,
0ede7366
IB
179 );
180 '';
4c4652aa 181 };
5ccc61bb 182 users.users.root.packages = let
10889174
IB
183 occ = pkgs.writeScriptBin "nextcloud-occ" ''
184 #! ${pkgs.stdenv.shell}
0ede7366
IB
185 cd ${nextcloud}
186 NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \
10889174 187 exec \
792ccef2
IB
188 sudo -E -u wwwrun ${phpPackage}/bin/php \
189 -c ${phpPackage}/etc/php.ini \
10889174
IB
190 occ $*
191 '';
192 in [ occ ];
193
0ede7366 194 system.activationScripts.nextcloud = {
3a1461cf
IB
195 deps = [ "secrets" ];
196 text = let
197 confs = lib.attrsets.mapAttrs (n: v: pkgs.writeText "${n}.json" (builtins.toJSON v)) nextcloud.otherConfig;
198 in
199 ''
0ede7366
IB
200 install -m 0755 -o wwwrun -g wwwrun -d ${varDir}
201 install -m 0750 -o wwwrun -g wwwrun -d ${varDir}/phpSessions
3a1461cf
IB
202 ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v:
203 "install -D -m 0644 -o wwwrun -g wwwrun -T ${v} ${varDir}/config/${n}.json"
204 ) confs)}
da30ae4f 205 #install -D -m 0600 -o wwwrun -g wwwrun -T ${config.secrets.fullPaths."webapps/tools-nextcloud"} ${varDir}/config/config.php
0ede7366
IB
206 '';
207 };
10889174 208
f40f5b23 209 services.phpfpm.pools.nextcloud = {
5400b9b6
IB
210 user = "wwwrun";
211 group = "wwwrun";
212 settings = phpFpm.pool;
792ccef2 213 inherit phpPackage;
10889174
IB
214 };
215
9c35092c
IB
216 services.cron = {
217 enable = true;
c418f62a
IB
218 systemCronJobs = let
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
792ccef2 223 ${phpPackage}/bin/php -d memory_limit=2048M -f ${nextcloud}/cron.php
c418f62a
IB
224 '';
225 in [
9c35092c 226 ''
c418f62a 227 */15 * * * * wwwrun ${script}/bin/nextcloud-cron
9c35092c
IB
228 ''
229 ];
230 };
10889174
IB
231 };
232}