diff options
Diffstat (limited to 'nixops/modules/websites/tools/cloud/default.nix')
-rw-r--r-- | nixops/modules/websites/tools/cloud/default.nix | 151 |
1 files changed, 136 insertions, 15 deletions
diff --git a/nixops/modules/websites/tools/cloud/default.nix b/nixops/modules/websites/tools/cloud/default.nix index 5c3e9a8..f7d25cf 100644 --- a/nixops/modules/websites/tools/cloud/default.nix +++ b/nixops/modules/websites/tools/cloud/default.nix | |||
@@ -1,10 +1,48 @@ | |||
1 | { lib, pkgs, config, myconfig, mylibs, ... }: | 1 | { lib, pkgs, config, myconfig, mylibs, ... }: |
2 | let | 2 | let |
3 | nextcloud = pkgs.callPackage ./nextcloud.nix { | 3 | nextcloud = pkgs.webapps.nextcloud.withApps (builtins.attrValues pkgs.webapps.nextcloud-apps); |
4 | env = myconfig.env.tools.nextcloud; | 4 | env = myconfig.env.tools.nextcloud; |
5 | }; | 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 | ||
6 | 41 | ||
7 | cfg = config.services.myWebsites.tools.cloud; | 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 | }; | ||
8 | in { | 46 | in { |
9 | options.services.myWebsites.tools.cloud = { | 47 | options.services.myWebsites.tools.cloud = { |
10 | enable = lib.mkEnableOption "enable cloud website"; | 48 | enable = lib.mkEnableOption "enable cloud website"; |
@@ -13,23 +51,98 @@ in { | |||
13 | config = lib.mkIf cfg.enable { | 51 | config = lib.mkIf cfg.enable { |
14 | security.acme.certs."eldiron".extraDomains."cloud.immae.eu" = null; | 52 | security.acme.certs."eldiron".extraDomains."cloud.immae.eu" = null; |
15 | 53 | ||
16 | services.myWebsites.tools.modules = nextcloud.apache.modules; | 54 | services.myWebsites.tools.modules = [ "proxy_fcgi" ]; |
17 | 55 | ||
18 | services.myWebsites.tools.vhostConfs.cloud = { | 56 | services.myWebsites.tools.vhostConfs.cloud = { |
19 | certName = "eldiron"; | 57 | certName = "eldiron"; |
20 | hosts = ["cloud.immae.eu" ]; | 58 | hosts = ["cloud.immae.eu" ]; |
21 | root = nextcloud.apache.root; | 59 | root = apacheRoot; |
22 | extraConfig = [ | 60 | extraConfig = [ |
23 | nextcloud.apache.vhostConf | 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 | '' | ||
24 | ]; | 80 | ]; |
25 | }; | 81 | }; |
26 | 82 | ||
27 | mySecrets.keys = nextcloud.keys; | 83 | mySecrets.keys = [{ |
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', | ||
97 | 'version' => '15.0.4.0', | ||
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', | ||
138 | ); | ||
139 | ''; | ||
140 | }]; | ||
28 | users.users.root.packages = let | 141 | users.users.root.packages = let |
29 | occ = pkgs.writeScriptBin "nextcloud-occ" '' | 142 | occ = pkgs.writeScriptBin "nextcloud-occ" '' |
30 | #! ${pkgs.stdenv.shell} | 143 | #! ${pkgs.stdenv.shell} |
31 | cd ${nextcloud.webRoot} | 144 | cd ${nextcloud} |
32 | NEXTCLOUD_CONFIG_DIR="${nextcloud.webRoot}/config" \ | 145 | NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \ |
33 | exec \ | 146 | exec \ |
34 | sudo -u wwwrun ${pkgs.php}/bin/php \ | 147 | sudo -u wwwrun ${pkgs.php}/bin/php \ |
35 | -c ${pkgs.php}/etc/php.ini \ | 148 | -c ${pkgs.php}/etc/php.ini \ |
@@ -37,15 +150,23 @@ in { | |||
37 | ''; | 150 | ''; |
38 | in [ occ ]; | 151 | in [ occ ]; |
39 | 152 | ||
40 | system.activationScripts.nextcloud = nextcloud.activationScript; | 153 | system.activationScripts.nextcloud = { |
154 | deps = [ ]; | ||
155 | text = '' | ||
156 | install -m 0755 -o wwwrun -g wwwrun -d ${varDir} | ||
157 | install -m 0750 -o wwwrun -g wwwrun -d ${varDir}/phpSessions | ||
158 | install -D -m 0644 -o wwwrun -g wwwrun ${./nextcloud-config}/* -t ${varDir}/config | ||
159 | install -D -m 0600 -o wwwrun -g wwwrun -T /var/secrets/webapps/tools-nextcloud ${varDir}/config/config.php | ||
160 | ''; | ||
161 | }; | ||
41 | system.extraSystemBuilderCmds = '' | 162 | system.extraSystemBuilderCmds = '' |
42 | mkdir -p $out/webapps | 163 | mkdir -p $out/webapps |
43 | ln -s ${nextcloud.webRoot} $out/webapps/${nextcloud.apache.webappName} | 164 | ln -s ${nextcloud} $out/webapps/${webappName} |
44 | ''; | 165 | ''; |
45 | 166 | ||
46 | services.myPhpfpm = { | 167 | services.myPhpfpm = { |
47 | poolPhpConfigs.nextcloud = nextcloud.phpFpm.phpConfig; | 168 | poolPhpConfigs.nextcloud = phpFpm.phpConfig; |
48 | poolConfigs.nextcloud = nextcloud.phpFpm.pool; | 169 | poolConfigs.nextcloud = phpFpm.pool; |
49 | }; | 170 | }; |
50 | 171 | ||
51 | services.cron = { | 172 | services.cron = { |
@@ -53,7 +174,7 @@ in { | |||
53 | systemCronJobs = [ | 174 | systemCronJobs = [ |
54 | '' | 175 | '' |
55 | LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive | 176 | LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive |
56 | */15 * * * * wwwrun ${pkgs.php}/bin/php -f ${nextcloud.webRoot}/cron.php | 177 | */15 * * * * wwwrun ${pkgs.php}/bin/php -f ${nextcloud}/cron.php |
57 | '' | 178 | '' |
58 | ]; | 179 | ]; |
59 | }; | 180 | }; |