aboutsummaryrefslogtreecommitdiff
path: root/nixops/modules/websites/tools/cloud
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-01-25 23:15:08 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-01-25 23:15:08 +0100
commit01f21083a897b86bf148f1d2bb9c8edca4d3786a (patch)
tree784f04e9b6ef99a49e572c84e4b7ab40b5eb5fde /nixops/modules/websites/tools/cloud
parentbfe3c9c9df0c5112bc8806483292b55ed0f7e02d (diff)
downloadNix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.tar.gz
Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.tar.zst
Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.zip
Rename virtual folder to nixops
Fixes https://git.immae.eu/mantisbt/view.php?id=82
Diffstat (limited to 'nixops/modules/websites/tools/cloud')
-rw-r--r--nixops/modules/websites/tools/cloud/default.nix47
-rw-r--r--nixops/modules/websites/tools/cloud/nextcloud-config/mimetypealiases.json4
-rw-r--r--nixops/modules/websites/tools/cloud/nextcloud-config/mimetypemapping.json4
-rw-r--r--nixops/modules/websites/tools/cloud/nextcloud.nix258
4 files changed, 313 insertions, 0 deletions
diff --git a/nixops/modules/websites/tools/cloud/default.nix b/nixops/modules/websites/tools/cloud/default.nix
new file mode 100644
index 0000000..241b982
--- /dev/null
+++ b/nixops/modules/websites/tools/cloud/default.nix
@@ -0,0 +1,47 @@
1{ lib, pkgs, config, myconfig, mylibs, ... }:
2let
3 nextcloud = pkgs.callPackage ./nextcloud.nix {
4 env = myconfig.env.tools.nextcloud;
5 };
6
7 cfg = config.services.myWebsites.tools.cloud;
8in {
9 options.services.myWebsites.tools.cloud = {
10 enable = lib.mkEnableOption "enable cloud website";
11 };
12
13 config = lib.mkIf cfg.enable {
14 security.acme.certs."eldiron".extraDomains."cloud.immae.eu" = null;
15
16 services.myWebsites.tools.modules = nextcloud.apache.modules;
17
18 services.myWebsites.tools.vhostConfs.cloud = {
19 certName = "eldiron";
20 hosts = ["cloud.immae.eu" ];
21 root = nextcloud.webRoot;
22 extraConfig = [
23 nextcloud.apache.vhostConf
24 ];
25 };
26
27 environment.systemPackages = let
28 occ = pkgs.writeScriptBin "nextcloud-occ" ''
29 #! ${pkgs.stdenv.shell}
30 cd ${nextcloud.webRoot}
31 NEXTCLOUD_CONFIG_DIR="${nextcloud.webRoot}/config" \
32 exec \
33 ${pkgs.php}/bin/php \
34 -c ${pkgs.php}/etc/php.ini \
35 occ $*
36 '';
37 in [ occ ];
38
39 system.activationScripts.nextcloud = nextcloud.activationScript;
40
41 services.myPhpfpm = {
42 poolPhpConfigs.nextcloud = nextcloud.phpFpm.phpConfig;
43 poolConfigs.nextcloud = nextcloud.phpFpm.pool;
44 };
45
46 };
47}
diff --git a/nixops/modules/websites/tools/cloud/nextcloud-config/mimetypealiases.json b/nixops/modules/websites/tools/cloud/nextcloud-config/mimetypealiases.json
new file mode 100644
index 0000000..3806e53
--- /dev/null
+++ b/nixops/modules/websites/tools/cloud/nextcloud-config/mimetypealiases.json
@@ -0,0 +1,4 @@
1{
2 "application/gpx+xml": "gpx",
3 "x-application/kdbx": "kdbx"
4}
diff --git a/nixops/modules/websites/tools/cloud/nextcloud-config/mimetypemapping.json b/nixops/modules/websites/tools/cloud/nextcloud-config/mimetypemapping.json
new file mode 100644
index 0000000..2db4691
--- /dev/null
+++ b/nixops/modules/websites/tools/cloud/nextcloud-config/mimetypemapping.json
@@ -0,0 +1,4 @@
1{
2 "gpx": ["application/gpx+xml"],
3 "kdbx": ["x-application/kdbx"]
4}
diff --git a/nixops/modules/websites/tools/cloud/nextcloud.nix b/nixops/modules/websites/tools/cloud/nextcloud.nix
new file mode 100644
index 0000000..3c6bfc9
--- /dev/null
+++ b/nixops/modules/websites/tools/cloud/nextcloud.nix
@@ -0,0 +1,258 @@
1{ stdenv, fetchurl, env, writeText, lib, phpPackages, php }:
2let
3 nextcloud = let
4 buildApp = { appName, version, url, sha256, installPhase ? "mkdir -p $out && cp -R . $out/" }:
5 stdenv.mkDerivation rec {
6 name = "nextcloud-app-${appName}-${version}";
7 inherit version;
8 phases = "unpackPhase installPhase";
9 inherit installPhase;
10 src = fetchurl { inherit url sha256; };
11 };
12 apps = {
13 audioplayer = buildApp rec {
14 appName = "audioplayer";
15 version = "2.5.0";
16 url = "https://github.com/Rello/${appName}/releases/download/${version}/${appName}-${version}.tar.gz";
17 sha256 = "1pg4y51cv3agy28n4gfc8i7x1ya1yijxrmhpblm1n846vhmwdcm8";
18 };
19 bookmarks = buildApp rec {
20 appName = "bookmarks";
21 version = "0.14.3";
22 url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}-${version}.tar.gz";
23 sha256 = "0s7lkcl70izlkihnml1par0cac0wvckllyyga3jkb7k9vdg7d40c";
24 };
25 calendar = buildApp rec {
26 appName = "calendar";
27 version = "1.6.4";
28 url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}.tar.gz";
29 sha256 = "00dijvcvy7snsjslfbyzvpp9anhms22zp1f0zkj89ln33jmana63";
30 };
31 contacts = buildApp rec {
32 appName = "contacts";
33 version = "3.0.0";
34 url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}.tar.gz";
35 sha256 = "0fafy5kgzr5ldr3hxxxgmnw4y3qpjnv5ha1f1dlmqbc65s8frw7s";
36 };
37 deck = buildApp rec {
38 appName = "deck";
39 version = "0.5.2";
40 url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}.tar.gz";
41 sha256 = "1kygzixxdkp3dbma009p3pw0fj8wgcqcv39n7pay78lh6zi3nic7";
42 };
43 files_markdown = buildApp rec {
44 appName = "files_markdown";
45 version = "2.0.5";
46 url = "https://github.com/icewind1991/${appName}/releases/download/v${version}/${appName}.tar.gz";
47 sha256 = "1dzvy4c6vff2qmkwqw13dx92xdkafaxgnipswjw44mh0ncc2n9ym";
48 };
49 gpxedit = buildApp rec {
50 appName = "gpxedit";
51 version = "0.0.10";
52 url = "https://gitlab.com/eneiluj/gpxedit-oc/wikis/uploads/33d187268c5f6f6a55350d656305701c/${appName}-${version}.tar.gz";
53 sha256 = "0ynpaxm0xhvcj8xax6rm1w0p6j57wbqidhi7bhn268n483gwl2sw";
54 };
55 gpxpod = buildApp rec {
56 appName = "gpxpod";
57 version = "3.0.0";
58 url = "https://gitlab.com/eneiluj/gpxpod-oc/-/archive/v${version}/${appName}-oc-v${version}.tar.gz";
59 sha256 = "0smpi4r3z7zfl1612fb30cwm1xmpiq95c81zzqiwzjf288iys74k";
60 };
61 keeweb = buildApp rec {
62 appName = "keeweb";
63 version = "0.4.0";
64 url = "https://github.com/jhass/nextcloud-keeweb/releases/download/v${version}/${appName}-${version}.tar.gz";
65 sha256 = "0453kkb0a8vfivmibpwpx4bvhyn64jhns6cdfjacmnvbm6d75nj1";
66 };
67 notes = buildApp rec {
68 appName = "notes";
69 version = "2.5.1";
70 url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}.tar.gz";
71 sha256 = "1albzqqsdirzyw8vhvs7r0qm2wqp8vm9vmxm4crhncd85bk01hmh";
72 };
73 ocsms = buildApp rec {
74 appName = "ocsms";
75 version = "2.1.0";
76 url = "https://github.com/nextcloud/${appName}/releases/download/${version}/${appName}-${version}.tar.gz";
77 sha256 = "19xgs82js4sdf6j9478vg9li7za7csvcaa1hbq9nmrq441sbxk9c";
78 installPhase = ''
79 sed -i -e "/addScript.*devel/d" -e "s@//\(.*addScript.*app.min\)@\1@" templates/main.php
80 mkdir -p $out
81 cp -R . $out/
82 '';
83 };
84 spreed = buildApp rec {
85 appName = "spreed";
86 version = "5.0.0";
87 url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}-${version}.tar.gz";
88 sha256 = "1d48mak1fnf1b28r2687yqamm4pxfg3qyxcj9ny31a6xg2cm0xa7";
89 };
90 tasks = buildApp rec {
91 appName = "tasks";
92 version = "0.9.8";
93 url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}.tar.gz";
94 sha256 = "089m124lfsfk09fqj50x9n7zndq97jp5afgb8s001rpmzym4g6ny";
95 };
96 };
97 in rec {
98 varDir = "/var/lib/nextcloud";
99 config_php = writeText "config.php" ''
100 <?php
101 $CONFIG = array (
102 'instanceid' => '${env.instance_id}',
103 'datadirectory' => '/var/lib/nextcloud/',
104 'passwordsalt' => '${env.password_salt}',
105 'debug' => false,
106 'dbtype' => 'pgsql',
107 'version' => '15.0.0.10',
108 'dbname' => '${env.postgresql.database}',
109 'dbhost' => '${env.postgresql.socket}',
110 'dbtableprefix' => 'oc_',
111 'dbuser' => '${env.postgresql.user}',
112 'dbpassword' => '${env.postgresql.password}',
113 'installed' => true,
114 'maxZipInputSize' => 0,
115 'allowZipDownload' => true,
116 'forcessl' => true,
117 'theme' => ${"''"},
118 'maintenance' => false,
119 'trusted_domains' =>
120 array (
121 0 => 'cloud.immae.eu',
122 ),
123 'secret' => '${env.secret}',
124 'appstoreenabled' => false,
125 'appstore.experimental.enabled' => true,
126 'loglevel' => 0,
127 'trashbin_retention_obligation' => 'auto',
128 'htaccess.RewriteBase' => '/',
129 'mail_smtpmode' => 'smtp',
130 'mail_smtphost' => 'mail.immae.eu',
131 'mail_smtpname' => ${"''"},
132 'mail_smtppassword' => ${"''"},
133 'mail_from_address' => 'owncloud',
134 'mail_smtpauth' => false,
135 'mail_domain' => 'immae.eu',
136 'memcache.local' => '\\OC\\Memcache\\APCu',
137 'memcache.locking' => '\\OC\\Memcache\\Redis',
138 'filelocking.enabled' => true,
139 'redis' =>
140 array (
141 'host' => '${env.redis.socket}',
142 'port' => 0,
143 'dbindex' => ${env.redis.db_index},
144 ),
145 'overwrite.cli.url' => 'https://cloud.immae.eu',
146 'ldapIgnoreNamingRules' => false,
147 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory',
148 'config_is_read_only' => true,
149 );
150 '';
151 config = stdenv.mkDerivation rec {
152 name = "nextcloud-config";
153 src = ./nextcloud-config;
154 phases = "installPhase";
155 installPhase = ''
156 mkdir -p $out
157 cp -r $src/* $out
158 cp ${config_php} $out/config.php
159 '';
160 };
161 webRoot = stdenv.mkDerivation rec {
162 name = "nextcloud-${version}";
163 version = "15.0.0";
164
165 src = fetchurl {
166 url = "https://download.nextcloud.com/server/releases/${name}.tar.bz2";
167 sha256 = "0y7bk1588n5rmmranmmrkajh50074460hr4v052ahg9mf60wbc2v";
168 };
169
170 installPhase = ''
171 mkdir -p $out/
172 cp -R . $out/
173 rm -r $out/config
174 ln -sf ${config} $out/config
175 ${builtins.concatStringsSep "\n" (
176 lib.attrsets.mapAttrsToList (name: value: "ln -sf ${value} $out/apps/${name}") apps
177 )}
178 '';
179
180 meta = {
181 description = "Sharing solution for files, calendars, contacts and more";
182 homepage = https://nextcloud.com;
183 maintainers = with lib.maintainers; [ schneefux bachp globin fpletz ];
184 license = lib.licenses.agpl3Plus;
185 platforms = with lib.platforms; unix;
186 };
187 };
188 activationScript = {
189 deps = [ ];
190 text = ''
191 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir}
192 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
193 '';
194 };
195 apache = {
196 user = "wwwrun";
197 group = "wwwrun";
198 modules = [ "proxy_fcgi" ];
199 vhostConf = ''
200 SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
201 <Directory ${webRoot}>
202 AcceptPathInfo On
203 DirectoryIndex index.php
204 Options FollowSymlinks
205 Require all granted
206 AllowOverride all
207
208 <IfModule mod_headers.c>
209 Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
210 </IfModule>
211 <FilesMatch "\.php$">
212 CGIPassAuth on
213 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
214 </FilesMatch>
215
216 </Directory>
217
218 '';
219 };
220 phpFpm = rec {
221 basedir = builtins.concatStringsSep ":" (
222 [ webRoot varDir config ]
223 ++ lib.attrsets.mapAttrsToList (name: value: value) apps);
224 socket = "/var/run/phpfpm/nextcloud.sock";
225 phpConfig = ''
226 extension=${phpPackages.redis}/lib/php/extensions/redis.so
227 extension=${phpPackages.apcu}/lib/php/extensions/apcu.so
228 zend_extension=${php}/lib/php/extensions/opcache.so
229 '';
230 pool = ''
231 listen = ${socket}
232 user = ${apache.user}
233 group = ${apache.group}
234 listen.owner = ${apache.user}
235 listen.group = ${apache.group}
236 pm = ondemand
237 pm.max_children = 60
238 pm.process_idle_timeout = 60
239
240 php_admin_value[output_buffering] = 0
241 php_admin_value[max_execution_time] = 1800
242 php_admin_value[zend_extension] = "opcache"
243 php_value[opcache.enable] = 1
244 php_value[opcache.enable_cli] = 1
245 php_value[opcache.interned_strings_buffer] = 8
246 php_value[opcache.max_accelerated_files] = 10000
247 php_value[opcache.memory_consumption] = 128
248 php_value[opcache.save_comments] = 1
249 php_value[opcache.revalidate_freq] = 1
250 php_admin_value[memory_limit] = 512M
251
252 php_admin_value[open_basedir] = "${basedir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp"
253 php_admin_value[session.save_path] = "${varDir}/phpSessions"
254 '';
255 };
256 };
257in
258 nextcloud