]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/system/quatresaisons/nextcloud.nix
Fix php-fpm that were on-demand instead of dynamic
[perso/Immae/Config/Nix.git] / modules / private / system / quatresaisons / nextcloud.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: [ a.calendar a.contacts ]);
8 varDir = "/var/lib/nextcloud";
9 phpFpm = rec {
10 basedir = builtins.concatStringsSep ":" ([ nextcloud varDir ] ++ nextcloud.apps);
11 pool = {
12 "listen.owner" = "wwwrun";
13 "listen.group" = "wwwrun";
14 "pm" = "dynamic";
15 "pm.start_servers" = "2";
16 "pm.min_spare_servers" = "1";
17 "pm.max_spare_servers" = "3";
18 "pm.max_children" = "60";
19 "pm.process_idle_timeout" = "60";
20
21 "php_admin_value[output_buffering]" = "0";
22 "php_admin_value[max_execution_time]" = "1800";
23 "php_admin_value[zend_extension]" = "opcache";
24 #already enabled by default?
25 #"php_value[opcache.enable]" = "1";
26 "php_value[opcache.enable_cli]" = "1";
27 "php_value[opcache.interned_strings_buffer]" = "8";
28 "php_value[opcache.max_accelerated_files]" = "10000";
29 "php_value[opcache.memory_consumption]" = "128";
30 "php_value[opcache.save_comments]" = "1";
31 "php_value[opcache.revalidate_freq]" = "1";
32 "php_admin_value[memory_limit]" = "512M";
33
34 "php_admin_value[open_basedir]" = "/run/wrappers/bin/sendmail:${basedir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp";
35 "php_admin_value[session.save_path]" = "${varDir}/phpSessions";
36 };
37 };
38 in {
39 config = {
40 services.postgresql.ensureDatabases = [ "nextcloud" ];
41 services.postgresql.ensureUsers = [
42 { name = "nextcloud"; ensurePermissions = { "DATABASE nextcloud" = "ALL PRIVILEGES"; }; }
43 ];
44 services.websites.env.production.modules = [ "proxy_fcgi" ];
45
46 services.websites.env.production.vhostConfs.cloud = {
47 certName = "quatresaisons";
48 addToCerts = true;
49 hosts = ["nextcloud.4c.salle-s.org" ];
50 root = nextcloud;
51 extraConfig =
52 [
53 ''
54 SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
55 <Directory ${nextcloud}>
56 AcceptPathInfo On
57 DirectoryIndex index.php
58 Options FollowSymlinks
59 Require all granted
60 AllowOverride all
61
62 <IfModule mod_headers.c>
63 Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
64 </IfModule>
65 <FilesMatch "\.php$">
66 CGIPassAuth on
67 SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud.socket}|fcgi://localhost"
68 </FilesMatch>
69
70 </Directory>
71 ''
72 ];
73 };
74 services.websites.env.production.vhostConfs.cloud_wait = let
75 content = pkgs.writeText "contenu" ''
76 nextcloud est un service qui a besoin de pérennité du nom
77 "nextcloud.salle-s.org", on va peut-etre y arriver, c'est une
78 question de jours, voir le message informatique.internet:8017
79 '';
80 in {
81 certName = "quatresaisons";
82 addToCerts = true;
83 hosts = ["nextcloud.salle-s.org" ];
84 root = content;
85 extraConfig =
86 [
87 ''
88 Alias / ${content}
89 ''
90 ];
91 };
92
93 users.users.root.packages = let
94 occ = pkgs.writeScriptBin "nextcloud-occ" ''
95 #! ${pkgs.stdenv.shell}
96 cd ${nextcloud}
97 NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \
98 exec \
99 sudo -E -u wwwrun ${phpPackage}/bin/php \
100 -c ${phpPackage}/etc/php.ini \
101 occ $*
102 '';
103 in [ occ ];
104
105 system.activationScripts.nextcloud = {
106 deps = [ "users" ];
107 text = let
108 confs = lib.attrsets.mapAttrs (n: v: pkgs.writeText "${n}.json" (builtins.toJSON v)) nextcloud.otherConfig;
109 in
110 ''
111 install -m 0755 -o wwwrun -g wwwrun -d ${varDir}
112 install -m 0755 -o wwwrun -g wwwrun -d ${varDir}/config
113 install -m 0750 -o wwwrun -g wwwrun -d ${varDir}/phpSessions
114 ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v:
115 "install -D -m 0644 -o wwwrun -g wwwrun -T ${v} ${varDir}/config/${n}.json"
116 ) confs)}
117 '';
118 };
119 services.phpfpm.pools.nextcloud = {
120 user = "wwwrun";
121 group = "wwwrun";
122 settings = phpFpm.pool;
123 inherit phpPackage;
124 };
125
126 services.cron = {
127 enable = true;
128 systemCronJobs = let
129 script = pkgs.writeScriptBin "nextcloud-cron" ''
130 #! ${pkgs.stdenv.shell}
131 export LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive
132 export PATH=/run/wrappers/bin:$PATH
133 ${phpPackage}/bin/php -d memory_limit=512M -f ${nextcloud}/cron.php
134 '';
135 in [
136 ''
137 */15 * * * * wwwrun ${script}/bin/nextcloud-cron
138 ''
139 ];
140 };
141 };
142 }