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