]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/websites/tools/cloud/default.nix
Bump Nextcloud to latest version
[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 {
29f8cb85 51 services.websites.env.tools.modules = [ "proxy_fcgi" ];
10889174 52
29f8cb85 53 services.websites.env.tools.vhostConfs.cloud = {
10889174 54 certName = "eldiron";
7df420c2 55 addToCerts = true;
10889174 56 hosts = ["cloud.immae.eu" ];
750fe5a4 57 root = nextcloud;
10889174 58 extraConfig = [
0ede7366
IB
59 ''
60 SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
750fe5a4 61 <Directory ${nextcloud}>
0ede7366
IB
62 AcceptPathInfo On
63 DirectoryIndex index.php
64 Options FollowSymlinks
65 Require all granted
66 AllowOverride all
67
68 <IfModule mod_headers.c>
69 Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
70 </IfModule>
71 <FilesMatch "\.php$">
72 CGIPassAuth on
5400b9b6 73 SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud.socket}|fcgi://localhost"
0ede7366
IB
74 </FilesMatch>
75
76 </Directory>
77 ''
10889174
IB
78 ];
79 };
80
4c4652aa 81 secrets.keys."webapps/tools-nextcloud" = {
0ede7366
IB
82 user = "wwwrun";
83 group = "wwwrun";
84 permissions = "0600";
c4216ddb 85 # This file is not actually included, see activationScript below
0ede7366
IB
86 text = ''
87 <?php
c4216ddb 88 include('${nextcloud}/version.php');
0ede7366
IB
89 $CONFIG = array (
90 // FIXME: change this value when nextcloud starts getting slow
50abe6fc 91 'instanceid' => '${env.instance_id}',
0ede7366
IB
92 'datadirectory' => '/var/lib/nextcloud/',
93 'passwordsalt' => '${env.password_salt}',
94 'debug' => false,
95 'dbtype' => 'pgsql',
c4216ddb 96 'version' => implode($OC_Version, '.'),
0ede7366
IB
97 'dbname' => '${env.postgresql.database}',
98 'dbhost' => '${env.postgresql.socket}',
99 'dbtableprefix' => 'oc_',
100 'dbuser' => '${env.postgresql.user}',
101 'dbpassword' => '${env.postgresql.password}',
102 'installed' => true,
103 'maxZipInputSize' => 0,
104 'allowZipDownload' => true,
105 'forcessl' => true,
106 'theme' => ${"''"},
792ccef2
IB
107 'remember_login_cookie_lifetime' => 60*60*24*30,
108 'session_keepalive' => true,
109 'session_lifefime' => 60*60*24*30,
0ede7366
IB
110 'maintenance' => false,
111 'trusted_domains' =>
112 array (
113 0 => 'cloud.immae.eu',
114 ),
115 'secret' => '${env.secret}',
116 'appstoreenabled' => false,
117 'appstore.experimental.enabled' => true,
118 'loglevel' => 2,
119 'trashbin_retention_obligation' => 'auto',
120 'htaccess.RewriteBase' => '/',
121 'mail_smtpmode' => 'sendmail',
122 'mail_smtphost' => '127.0.0.1',
123 'mail_smtpname' => ''',
124 'mail_smtppassword' => ''',
125 'mail_from_address' => 'nextcloud',
126 'mail_smtpauth' => false,
127 'mail_domain' => 'tools.immae.eu',
128 'memcache.local' => '\\OC\\Memcache\\APCu',
129 'memcache.locking' => '\\OC\\Memcache\\Redis',
130 'filelocking.enabled' => true,
131 'redis' =>
132 array (
133 'host' => '${env.redis.socket}',
134 'port' => 0,
ab8f306d 135 'dbindex' => ${env.redis.db},
0ede7366
IB
136 ),
137 'overwrite.cli.url' => 'https://cloud.immae.eu',
138 'ldapIgnoreNamingRules' => false,
139 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
3a1461cf 140 'has_rebuilt_cache' => true,
0ede7366
IB
141 );
142 '';
4c4652aa 143 };
5ccc61bb 144 users.users.root.packages = let
10889174
IB
145 occ = pkgs.writeScriptBin "nextcloud-occ" ''
146 #! ${pkgs.stdenv.shell}
0ede7366
IB
147 cd ${nextcloud}
148 NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \
10889174 149 exec \
792ccef2
IB
150 sudo -E -u wwwrun ${phpPackage}/bin/php \
151 -c ${phpPackage}/etc/php.ini \
10889174
IB
152 occ $*
153 '';
154 in [ occ ];
155
0ede7366 156 system.activationScripts.nextcloud = {
3a1461cf
IB
157 deps = [ "secrets" ];
158 text = let
159 confs = lib.attrsets.mapAttrs (n: v: pkgs.writeText "${n}.json" (builtins.toJSON v)) nextcloud.otherConfig;
160 in
161 ''
0ede7366
IB
162 install -m 0755 -o wwwrun -g wwwrun -d ${varDir}
163 install -m 0750 -o wwwrun -g wwwrun -d ${varDir}/phpSessions
3a1461cf
IB
164 ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v:
165 "install -D -m 0644 -o wwwrun -g wwwrun -T ${v} ${varDir}/config/${n}.json"
166 ) confs)}
da30ae4f 167 #install -D -m 0600 -o wwwrun -g wwwrun -T ${config.secrets.fullPaths."webapps/tools-nextcloud"} ${varDir}/config/config.php
0ede7366
IB
168 '';
169 };
10889174 170
f40f5b23 171 services.phpfpm.pools.nextcloud = {
5400b9b6
IB
172 user = "wwwrun";
173 group = "wwwrun";
174 settings = phpFpm.pool;
792ccef2 175 inherit phpPackage;
10889174
IB
176 };
177
9c35092c
IB
178 services.cron = {
179 enable = true;
c418f62a
IB
180 systemCronJobs = let
181 script = pkgs.writeScriptBin "nextcloud-cron" ''
182 #! ${pkgs.stdenv.shell}
183 export LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive
184 export PATH=/run/wrappers/bin:$PATH
792ccef2 185 ${phpPackage}/bin/php -d memory_limit=2048M -f ${nextcloud}/cron.php
c418f62a
IB
186 '';
187 in [
9c35092c 188 ''
c418f62a 189 */15 * * * * wwwrun ${script}/bin/nextcloud-cron
9c35092c
IB
190 ''
191 ];
192 };
10889174
IB
193 };
194}