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