]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/tools/cloud/default.nix
Remove some handled fixme comments
[perso/Immae/Config/Nix.git] / modules / private / websites / tools / cloud / default.nix
1 { lib, pkgs, config, ... }:
2 let
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 ]);
9 env = config.myEnv.tools.nextcloud;
10 varDir = "/var/lib/nextcloud";
11 webappName = "tools_nextcloud";
12 apacheRoot = "/run/current-system/webapps/${webappName}";
13 cfg = config.myServices.websites.tools.cloud;
14 phpFpm = rec {
15 basedir = builtins.concatStringsSep ":" ([ nextcloud varDir ] ++ nextcloud.apps);
16 pool = {
17 "listen.owner" = "wwwrun";
18 "listen.group" = "wwwrun";
19 "pm" = "ondemand";
20 "pm.max_children" = "60";
21 "pm.process_idle_timeout" = "60";
22
23 "php_admin_value[output_buffering]" = "0";
24 "php_admin_value[max_execution_time]" = "1800";
25 "php_admin_value[zend_extension]" = "opcache";
26 #already enabled by default?
27 #"php_value[opcache.enable]" = "1";
28 "php_value[opcache.enable_cli]" = "1";
29 "php_value[opcache.interned_strings_buffer]" = "8";
30 "php_value[opcache.max_accelerated_files]" = "10000";
31 "php_value[opcache.memory_consumption]" = "128";
32 "php_value[opcache.save_comments]" = "1";
33 "php_value[opcache.revalidate_freq]" = "1";
34 "php_admin_value[memory_limit]" = "512M";
35
36 "php_admin_value[open_basedir]" = "/run/wrappers/bin/sendmail:${basedir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp";
37 "php_admin_value[session.save_path]" = "${varDir}/phpSessions";
38 };
39 };
40 in {
41 options.myServices.websites.tools.cloud = {
42 enable = lib.mkEnableOption "enable cloud website";
43 };
44
45 config = lib.mkIf cfg.enable {
46 services.websites.env.tools.modules = [ "proxy_fcgi" ];
47
48 services.websites.env.tools.vhostConfs.cloud = {
49 certName = "eldiron";
50 addToCerts = true;
51 hosts = ["cloud.immae.eu" ];
52 root = apacheRoot;
53 extraConfig = [
54 ''
55 SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
56 <Directory ${apacheRoot}>
57 AcceptPathInfo On
58 DirectoryIndex index.php
59 Options FollowSymlinks
60 Require all granted
61 AllowOverride all
62
63 <IfModule mod_headers.c>
64 Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
65 </IfModule>
66 <FilesMatch "\.php$">
67 CGIPassAuth on
68 SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud.socket}|fcgi://localhost"
69 </FilesMatch>
70
71 </Directory>
72 ''
73 ];
74 };
75
76 secrets.keys = [{
77 dest = "webapps/tools-nextcloud";
78 user = "wwwrun";
79 group = "wwwrun";
80 permissions = "0600";
81 # This file is not actually included, see activationScript below
82 text = ''
83 <?php
84 include('${nextcloud}/version.php');
85 $CONFIG = array (
86 // FIXME: change this value when nextcloud starts getting slow
87 'instanceid' => '${env.instance_id}1',
88 'datadirectory' => '/var/lib/nextcloud/',
89 'passwordsalt' => '${env.password_salt}',
90 'debug' => false,
91 'dbtype' => 'pgsql',
92 'version' => implode($OC_Version, '.'),
93 'dbname' => '${env.postgresql.database}',
94 'dbhost' => '${env.postgresql.socket}',
95 'dbtableprefix' => 'oc_',
96 'dbuser' => '${env.postgresql.user}',
97 'dbpassword' => '${env.postgresql.password}',
98 'installed' => true,
99 'maxZipInputSize' => 0,
100 'allowZipDownload' => true,
101 'forcessl' => true,
102 'theme' => ${"''"},
103 'maintenance' => false,
104 'trusted_domains' =>
105 array (
106 0 => 'cloud.immae.eu',
107 ),
108 'secret' => '${env.secret}',
109 'appstoreenabled' => false,
110 'appstore.experimental.enabled' => true,
111 'loglevel' => 2,
112 'trashbin_retention_obligation' => 'auto',
113 'htaccess.RewriteBase' => '/',
114 'mail_smtpmode' => 'sendmail',
115 'mail_smtphost' => '127.0.0.1',
116 'mail_smtpname' => ''',
117 'mail_smtppassword' => ''',
118 'mail_from_address' => 'nextcloud',
119 'mail_smtpauth' => false,
120 'mail_domain' => 'tools.immae.eu',
121 'memcache.local' => '\\OC\\Memcache\\APCu',
122 'memcache.locking' => '\\OC\\Memcache\\Redis',
123 'filelocking.enabled' => true,
124 'redis' =>
125 array (
126 'host' => '${env.redis.socket}',
127 'port' => 0,
128 'dbindex' => ${env.redis.db},
129 ),
130 'overwrite.cli.url' => 'https://cloud.immae.eu',
131 'ldapIgnoreNamingRules' => false,
132 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
133 'has_rebuilt_cache' => true,
134 );
135 '';
136 }];
137 users.users.root.packages = let
138 occ = pkgs.writeScriptBin "nextcloud-occ" ''
139 #! ${pkgs.stdenv.shell}
140 cd ${nextcloud}
141 NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \
142 exec \
143 sudo -u wwwrun ${pkgs.php74}/bin/php \
144 -c ${pkgs.php74}/etc/php.ini \
145 occ $*
146 '';
147 in [ occ ];
148
149 system.activationScripts.nextcloud = {
150 deps = [ "secrets" ];
151 text = let
152 confs = lib.attrsets.mapAttrs (n: v: pkgs.writeText "${n}.json" (builtins.toJSON v)) nextcloud.otherConfig;
153 in
154 ''
155 install -m 0755 -o wwwrun -g wwwrun -d ${varDir}
156 install -m 0750 -o wwwrun -g wwwrun -d ${varDir}/phpSessions
157 ${builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v:
158 "install -D -m 0644 -o wwwrun -g wwwrun -T ${v} ${varDir}/config/${n}.json"
159 ) confs)}
160 #install -D -m 0600 -o wwwrun -g wwwrun -T /var/secrets/webapps/tools-nextcloud ${varDir}/config/config.php
161 '';
162 };
163 # FIXME: add a warning when config.php changes
164 system.extraSystemBuilderCmds = ''
165 mkdir -p $out/webapps
166 ln -s ${nextcloud} $out/webapps/${webappName}
167 '';
168
169 services.phpfpm.pools.nextcloud = {
170 user = "wwwrun";
171 group = "wwwrun";
172 settings = phpFpm.pool;
173 phpPackage = pkgs.php74.withExtensions({ enabled, all }: enabled ++ [ all.redis all.apcu all.opcache ]);
174 };
175
176 services.cron = {
177 enable = true;
178 systemCronJobs = let
179 script = pkgs.writeScriptBin "nextcloud-cron" ''
180 #! ${pkgs.stdenv.shell}
181 export LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive
182 export PATH=/run/wrappers/bin:$PATH
183 ${pkgs.php74}/bin/php -d memory_limit=512M -f ${nextcloud}/cron.php
184 '';
185 in [
186 ''
187 */15 * * * * wwwrun ${script}/bin/nextcloud-cron
188 ''
189 ];
190 };
191 };
192 }