]>
Commit | Line | Data |
---|---|---|
ab8f306d | 1 | { lib, pkgs, config, ... }: |
10889174 | 2 | let |
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 | 41 | "php_admin_value[open_basedir]" = "/run/wrappers/bin/sendmail:${basedir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp"; |
bbea22c0 IB |
42 | "php_admin_value[session.save_handler]" = "redis"; |
43 | "php_admin_value[session.save_path]" = "'unix:///run/redis-php-sessions/redis.sock?persistent=1&prefix=Tools:Nextcloud:'"; | |
5400b9b6 | 44 | }; |
0ede7366 | 45 | }; |
10889174 | 46 | in { |
4288c2f2 | 47 | options.myServices.websites.tools.cloud = { |
10889174 IB |
48 | enable = lib.mkEnableOption "enable cloud website"; |
49 | }; | |
50 | ||
51 | config = lib.mkIf cfg.enable { | |
120bcf4d IB |
52 | myServices.chatonsProperties.hostings.nextcloud = { |
53 | file.datetime = "2022-08-21T19:50:00"; | |
54 | hosting = { | |
55 | name = "Nextcloud"; | |
56 | description = "The self-hosted productivity platform that keeps you in control"; | |
57 | website = "https://cloud.immae.eu/"; | |
58 | logo = "https://cloud.immae.eu/core/img/favicon.ico"; | |
59 | type = "INSTANCE"; | |
60 | status.level = "OK"; | |
61 | status.description = "OK"; | |
62 | registration.load = "OPEN"; | |
63 | install.type = "PACKAGE"; | |
64 | }; | |
65 | }; | |
66 | myServices.chatonsProperties.services.nextcloud = { | |
67 | file.datetime = "2022-08-21T19:50:00"; | |
68 | service = { | |
69 | name = "Nextcloud"; | |
70 | description = "The self-hosted productivity platform that keeps you in control"; | |
71 | website = "https://cloud.immae.eu/"; | |
72 | logo = "https://cloud.immae.eu/core/img/favicon.ico"; | |
73 | status.level = "OK"; | |
74 | status.description = "OK"; | |
75 | registration."" = ["MEMBER" "CLIENT"]; | |
76 | registration.load = "OPEN"; | |
77 | install.type = "PACKAGE"; | |
78 | guide.user = "https://www.immae.eu/docs/nextcloud.html"; | |
79 | }; | |
80 | software = { | |
81 | name = "Nextcloud"; | |
82 | website = "https://nextcloud.com/"; | |
83 | license.url = "https://github.com/nextcloud/server/blob/master/COPYING"; | |
84 | license.name = "GNU Affero General Public License v3.0"; | |
85 | version = nextcloud.version; | |
86 | source.url = "https://github.com/nextcloud/server"; | |
87 | modules = map (a: a.appName) nextcloud.apps; | |
88 | }; | |
89 | }; | |
29f8cb85 | 90 | services.websites.env.tools.modules = [ "proxy_fcgi" ]; |
10889174 | 91 | |
29f8cb85 | 92 | services.websites.env.tools.vhostConfs.cloud = { |
10889174 | 93 | certName = "eldiron"; |
7df420c2 | 94 | addToCerts = true; |
10889174 | 95 | hosts = ["cloud.immae.eu" ]; |
750fe5a4 | 96 | root = nextcloud; |
10889174 | 97 | extraConfig = [ |
0ede7366 IB |
98 | '' |
99 | SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 | |
750fe5a4 | 100 | <Directory ${nextcloud}> |
0ede7366 IB |
101 | AcceptPathInfo On |
102 | DirectoryIndex index.php | |
103 | Options FollowSymlinks | |
104 | Require all granted | |
105 | AllowOverride all | |
106 | ||
107 | <IfModule mod_headers.c> | |
108 | Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload" | |
109 | </IfModule> | |
110 | <FilesMatch "\.php$"> | |
111 | CGIPassAuth on | |
5400b9b6 | 112 | SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud.socket}|fcgi://localhost" |
0ede7366 IB |
113 | </FilesMatch> |
114 | ||
115 | </Directory> | |
116 | '' | |
10889174 IB |
117 | ]; |
118 | }; | |
119 | ||
4c4652aa | 120 | secrets.keys."webapps/tools-nextcloud" = { |
0ede7366 IB |
121 | user = "wwwrun"; |
122 | group = "wwwrun"; | |
123 | permissions = "0600"; | |
c4216ddb | 124 | # This file is not actually included, see activationScript below |
0ede7366 IB |
125 | text = '' |
126 | <?php | |
c4216ddb | 127 | include('${nextcloud}/version.php'); |
0ede7366 IB |
128 | $CONFIG = array ( |
129 | // FIXME: change this value when nextcloud starts getting slow | |
50abe6fc | 130 | 'instanceid' => '${env.instance_id}', |
0ede7366 IB |
131 | 'datadirectory' => '/var/lib/nextcloud/', |
132 | 'passwordsalt' => '${env.password_salt}', | |
133 | 'debug' => false, | |
134 | 'dbtype' => 'pgsql', | |
c4216ddb | 135 | 'version' => implode($OC_Version, '.'), |
0ede7366 IB |
136 | 'dbname' => '${env.postgresql.database}', |
137 | 'dbhost' => '${env.postgresql.socket}', | |
138 | 'dbtableprefix' => 'oc_', | |
139 | 'dbuser' => '${env.postgresql.user}', | |
140 | 'dbpassword' => '${env.postgresql.password}', | |
141 | 'installed' => true, | |
142 | 'maxZipInputSize' => 0, | |
143 | 'allowZipDownload' => true, | |
144 | 'forcessl' => true, | |
145 | 'theme' => ${"''"}, | |
792ccef2 IB |
146 | 'remember_login_cookie_lifetime' => 60*60*24*30, |
147 | 'session_keepalive' => true, | |
148 | 'session_lifefime' => 60*60*24*30, | |
0ede7366 IB |
149 | 'maintenance' => false, |
150 | 'trusted_domains' => | |
151 | array ( | |
152 | 0 => 'cloud.immae.eu', | |
153 | ), | |
154 | 'secret' => '${env.secret}', | |
155 | 'appstoreenabled' => false, | |
156 | 'appstore.experimental.enabled' => true, | |
157 | 'loglevel' => 2, | |
158 | 'trashbin_retention_obligation' => 'auto', | |
159 | 'htaccess.RewriteBase' => '/', | |
160 | 'mail_smtpmode' => 'sendmail', | |
161 | 'mail_smtphost' => '127.0.0.1', | |
162 | 'mail_smtpname' => ''', | |
163 | 'mail_smtppassword' => ''', | |
164 | 'mail_from_address' => 'nextcloud', | |
165 | 'mail_smtpauth' => false, | |
166 | 'mail_domain' => 'tools.immae.eu', | |
167 | 'memcache.local' => '\\OC\\Memcache\\APCu', | |
168 | 'memcache.locking' => '\\OC\\Memcache\\Redis', | |
169 | 'filelocking.enabled' => true, | |
170 | 'redis' => | |
171 | array ( | |
172 | 'host' => '${env.redis.socket}', | |
173 | 'port' => 0, | |
ab8f306d | 174 | 'dbindex' => ${env.redis.db}, |
0ede7366 IB |
175 | ), |
176 | 'overwrite.cli.url' => 'https://cloud.immae.eu', | |
177 | 'ldapIgnoreNamingRules' => false, | |
178 | 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory', | |
3a1461cf | 179 | 'has_rebuilt_cache' => true, |
0ede7366 IB |
180 | ); |
181 | ''; | |
4c4652aa | 182 | }; |
5ccc61bb | 183 | users.users.root.packages = let |
10889174 IB |
184 | occ = pkgs.writeScriptBin "nextcloud-occ" '' |
185 | #! ${pkgs.stdenv.shell} | |
0ede7366 IB |
186 | cd ${nextcloud} |
187 | NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \ | |
10889174 | 188 | exec \ |
792ccef2 IB |
189 | sudo -E -u wwwrun ${phpPackage}/bin/php \ |
190 | -c ${phpPackage}/etc/php.ini \ | |
10889174 IB |
191 | occ $* |
192 | ''; | |
193 | in [ occ ]; | |
194 | ||
0ede7366 | 195 | system.activationScripts.nextcloud = { |
3a1461cf IB |
196 | deps = [ "secrets" ]; |
197 | text = let | |
198 | confs = lib.attrsets.mapAttrs (n: v: pkgs.writeText "${n}.json" (builtins.toJSON v)) nextcloud.otherConfig; | |
199 | in | |
200 | '' | |
0ede7366 | 201 | install -m 0755 -o wwwrun -g wwwrun -d ${varDir} |
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 | } |