]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/tools/cloud/default.nix
Bump Nextcloud to latest version
[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 services.websites.env.tools.modules = [ "proxy_fcgi" ];
52
53 services.websites.env.tools.vhostConfs.cloud = {
54 certName = "eldiron";
55 addToCerts = true;
56 hosts = ["cloud.immae.eu" ];
57 root = nextcloud;
58 extraConfig = [
59 ''
60 SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
61 <Directory ${nextcloud}>
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
73 SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud.socket}|fcgi://localhost"
74 </FilesMatch>
75
76 </Directory>
77 ''
78 ];
79 };
80
81 secrets.keys."webapps/tools-nextcloud" = {
82 user = "wwwrun";
83 group = "wwwrun";
84 permissions = "0600";
85 # This file is not actually included, see activationScript below
86 text = ''
87 <?php
88 include('${nextcloud}/version.php');
89 $CONFIG = array (
90 // FIXME: change this value when nextcloud starts getting slow
91 'instanceid' => '${env.instance_id}',
92 'datadirectory' => '/var/lib/nextcloud/',
93 'passwordsalt' => '${env.password_salt}',
94 'debug' => false,
95 'dbtype' => 'pgsql',
96 'version' => implode($OC_Version, '.'),
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' => ${"''"},
107 'remember_login_cookie_lifetime' => 60*60*24*30,
108 'session_keepalive' => true,
109 'session_lifefime' => 60*60*24*30,
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,
135 'dbindex' => ${env.redis.db},
136 ),
137 'overwrite.cli.url' => 'https://cloud.immae.eu',
138 'ldapIgnoreNamingRules' => false,
139 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
140 'has_rebuilt_cache' => true,
141 );
142 '';
143 };
144 users.users.root.packages = let
145 occ = pkgs.writeScriptBin "nextcloud-occ" ''
146 #! ${pkgs.stdenv.shell}
147 cd ${nextcloud}
148 NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \
149 exec \
150 sudo -E -u wwwrun ${phpPackage}/bin/php \
151 -c ${phpPackage}/etc/php.ini \
152 occ $*
153 '';
154 in [ occ ];
155
156 system.activationScripts.nextcloud = {
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 ''
162 install -m 0755 -o wwwrun -g wwwrun -d ${varDir}
163 install -m 0750 -o wwwrun -g wwwrun -d ${varDir}/phpSessions
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)}
167 #install -D -m 0600 -o wwwrun -g wwwrun -T ${config.secrets.fullPaths."webapps/tools-nextcloud"} ${varDir}/config/config.php
168 '';
169 };
170
171 services.phpfpm.pools.nextcloud = {
172 user = "wwwrun";
173 group = "wwwrun";
174 settings = phpFpm.pool;
175 inherit phpPackage;
176 };
177
178 services.cron = {
179 enable = true;
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
185 ${phpPackage}/bin/php -d memory_limit=2048M -f ${nextcloud}/cron.php
186 '';
187 in [
188 ''
189 */15 * * * * wwwrun ${script}/bin/nextcloud-cron
190 ''
191 ];
192 };
193 };
194 }