]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/tools/cloud/default.nix
Add chatons infos
[perso/Immae/Config/Nix.git] / modules / private / websites / tools / cloud / default.nix
1 { lib, pkgs, config, ... }:
2 let
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: [
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
12 ]);
13 env = config.myEnv.tools.nextcloud;
14 varDir = "/var/lib/nextcloud";
15 cfg = config.myServices.websites.tools.cloud;
16 phpFpm = rec {
17 basedir = builtins.concatStringsSep ":" ([ nextcloud varDir ] ++ nextcloud.apps);
18 pool = {
19 "listen.owner" = "wwwrun";
20 "listen.group" = "wwwrun";
21 "pm" = "dynamic";
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";
27
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";
40
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 };
44 };
45 in {
46 options.myServices.websites.tools.cloud = {
47 enable = lib.mkEnableOption "enable cloud website";
48 };
49
50 config = lib.mkIf cfg.enable {
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 };
89 services.websites.env.tools.modules = [ "proxy_fcgi" ];
90
91 services.websites.env.tools.vhostConfs.cloud = {
92 certName = "eldiron";
93 addToCerts = true;
94 hosts = ["cloud.immae.eu" ];
95 root = nextcloud;
96 extraConfig = [
97 ''
98 SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
99 <Directory ${nextcloud}>
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
111 SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud.socket}|fcgi://localhost"
112 </FilesMatch>
113
114 </Directory>
115 ''
116 ];
117 };
118
119 secrets.keys."webapps/tools-nextcloud" = {
120 user = "wwwrun";
121 group = "wwwrun";
122 permissions = "0600";
123 # This file is not actually included, see activationScript below
124 text = ''
125 <?php
126 include('${nextcloud}/version.php');
127 $CONFIG = array (
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}',
132 'debug' => false,
133 'dbtype' => 'pgsql',
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}',
140 'installed' => true,
141 'maxZipInputSize' => 0,
142 'allowZipDownload' => true,
143 'forcessl' => true,
144 'theme' => ${"''"},
145 'remember_login_cookie_lifetime' => 60*60*24*30,
146 'session_keepalive' => true,
147 'session_lifefime' => 60*60*24*30,
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,
173 'dbindex' => ${env.redis.db},
174 ),
175 'overwrite.cli.url' => 'https://cloud.immae.eu',
176 'ldapIgnoreNamingRules' => false,
177 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
178 'has_rebuilt_cache' => true,
179 );
180 '';
181 };
182 users.users.root.packages = let
183 occ = pkgs.writeScriptBin "nextcloud-occ" ''
184 #! ${pkgs.stdenv.shell}
185 cd ${nextcloud}
186 NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \
187 exec \
188 sudo -E -u wwwrun ${phpPackage}/bin/php \
189 -c ${phpPackage}/etc/php.ini \
190 occ $*
191 '';
192 in [ occ ];
193
194 system.activationScripts.nextcloud = {
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 ''
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"
204 ) confs)}
205 #install -D -m 0600 -o wwwrun -g wwwrun -T ${config.secrets.fullPaths."webapps/tools-nextcloud"} ${varDir}/config/config.php
206 '';
207 };
208
209 services.phpfpm.pools.nextcloud = {
210 user = "wwwrun";
211 group = "wwwrun";
212 settings = phpFpm.pool;
213 inherit phpPackage;
214 };
215
216 services.cron = {
217 enable = true;
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
223 ${phpPackage}/bin/php -d memory_limit=2048M -f ${nextcloud}/cron.php
224 '';
225 in [
226 ''
227 */15 * * * * wwwrun ${script}/bin/nextcloud-cron
228 ''
229 ];
230 };
231 };
232 }