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