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