]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/modules/websites/tools/ether/etherpad_lite.nix
Refactor configuration and overlays
[perso/Immae/Config/Nix.git] / nixops / modules / websites / tools / ether / etherpad_lite.nix
CommitLineData
17146204
IB
1{ env, fetchedGithub, fetchurl, stdenv, writeText, pkgs, cacert }:
2let
bfe3c9c9 3 listenPort = env.listenPort;
17146204
IB
4 sessionkey = writeText "SESSIONKEY.txt" env.session_key;
5 apikey = writeText "APIKEY.txt" env.api_key;
6 jquery = fetchurl {
7 url = https://code.jquery.com/jquery-1.9.1.js;
8 sha256 = "0h4dk67yc9d0kadqxb6b33585f3x3559p6qmp70l00qwq030vn3v";
9 };
10 etherpad_modules = [
11 "ep_aa_file_menu_toolbar"
12 "ep_adminpads"
13 "ep_align"
14 "ep_bookmark"
15 "ep_clear_formatting"
16 "ep_colors"
17 "ep_copy_paste_select_all"
18 "ep_cursortrace"
19 "ep_embedmedia"
20 "ep_font_family"
21 "ep_font_size"
22 "ep_headings2"
23 "ep_ldapauth"
24 "ep_line_height"
25 "ep_markdown"
26 "ep_previewimages"
27 "ep_ruler"
28 "ep_scrollto"
29 "ep_set_title_on_pad"
30 "ep_subscript_and_superscript"
31 "ep_timesliderdiff"
32 ];
32c84ff8
IB
33 keys = [
34 {
35 dest = "webapps/tools-etherpad-apikey";
e905cd0b
IB
36 permissions = "0400";
37 text = env.api_key;
32c84ff8
IB
38 }
39 {
40 dest = "webapps/tools-etherpad-sessionkey";
e905cd0b
IB
41 permissions = "0400";
42 text = env.session_key;
32c84ff8
IB
43 }
44 {
45 dest = "webapps/tools-etherpad";
e905cd0b
IB
46 permissions = "0400";
47 text =
48 # Make sure we’re not rebuilding whole libreoffice just because of a
49 # dependency
fdf6f74d 50 let libreoffice = (import <nixpkgs> { overlays = []; }).libreoffice-fresh;
e905cd0b
IB
51 in
52 ''
53 {
54 "title": "Etherpad",
55 "favicon": "favicon.ico",
17146204 56
e905cd0b
IB
57 "ip": "127.0.0.1",
58 "port" : ${env.listenPort},
59 "showSettingsInAdminPage" : false,
60 "dbType" : "postgres",
61 "dbSettings" : {
62 "user" : "${env.postgresql.user}",
63 "host" : "${env.postgresql.socket}",
64 "password": "${env.postgresql.password}",
65 "database": "${env.postgresql.database}",
66 "charset" : "utf8mb4"
67 },
17146204 68
e905cd0b
IB
69 "defaultPadText" : "Welcome to Etherpad!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nGet involved with Etherpad at http:\/\/etherpad.org\n",
70 "padOptions": {
71 "noColors": false,
72 "showControls": true,
73 "showChat": true,
74 "showLineNumbers": true,
75 "useMonospaceFont": false,
76 "userName": false,
77 "userColor": false,
78 "rtl": false,
79 "alwaysShowChat": false,
80 "chatAndUsers": false,
81 "lang": "en-gb"
82 },
17146204 83
e905cd0b
IB
84 "suppressErrorsInPadText" : false,
85 "requireSession" : false,
86 "editOnly" : false,
87 "sessionNoPassword" : false,
88 "minify" : true,
89 "maxAge" : 21600,
90 "abiword" : null,
91 "soffice" : "${libreoffice}/bin/soffice",
92 "tidyHtml" : "${pkgs.html-tidy}/bin/tidy",
93 "allowUnknownFileEnds" : true,
94 "requireAuthentication" : false,
95 "requireAuthorization" : false,
96 "trustProxy" : false,
97 "disableIPlogging" : false,
98 "automaticReconnectionTimeout" : 0,
99 "scrollWhenFocusLineIsOutOfViewport": {
100 "percentage": {
101 "editionAboveViewport": 0,
102 "editionBelowViewport": 0
103 },
104 "duration": 0,
105 "scrollWhenCaretIsInTheLastLineOfViewport": false,
106 "percentageToScrollWhenUserPressesArrowUp": 0
51900e34 107 },
e905cd0b
IB
108 "users": {
109 "ldapauth": {
110 "url": "ldaps://${env.ldap.host}",
111 "accountBase": "${env.ldap.base}",
112 "accountPattern": "(&(memberOf=cn=users,cn=etherpad,ou=services,dc=immae,dc=eu)(uid={{username}}))",
113 "displayNameAttribute": "cn",
114 "searchDN": "cn=etherpad,ou=services,dc=immae,dc=eu",
115 "searchPWD": "${env.ldap.password}",
116 "groupSearchBase": "${env.ldap.base}",
117 "groupAttribute": "member",
118 "groupAttributeIsDN": true,
119 "searchScope": "sub",
120 "groupSearch": "(memberOf=cn=groups,cn=etherpad,ou=services,dc=immae,dc=eu)",
121 "anonymousReadonly": false
122 }
123 },
124 "socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],
125 "loadTest": false,
126 "indentationOnNewLine": false,
127 "toolbar": {
128 "left": [
129 ["bold", "italic", "underline", "strikethrough"],
130 ["orderedlist", "unorderedlist", "indent", "outdent"],
131 ["undo", "redo"],
132 ["clearauthorship"]
133 ],
134 "right": [
135 ["importexport", "timeslider", "savedrevision"],
136 ["settings", "embed"],
137 ["showusers"]
138 ],
139 "timeslider": [
140 ["timeslider_export", "timeslider_returnToPad"]
141 ]
142 },
143 "loglevel": "INFO",
144 "logconfig" : { "appenders": [ { "type": "console" } ] }
145 }
146 '';
32c84ff8
IB
147 }
148 ];
17146204
IB
149 webappDir = stdenv.mkDerivation (fetchedGithub ./etherpad-lite.json // rec {
150 __noChroot = true;
151 patches = [ ./libreoffice_patch.diff ];
152 buildPhase = ''
153 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
154 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
155 export HOME=$PWD
156
157 touch src/.ep_initialized
158 cp -v src/static/custom/js.template src/static/custom/index.js
159 cp -v src/static/custom/js.template src/static/custom/pad.js
160 cp -v src/static/custom/js.template src/static/custom/timeslider.js
161 cp -v src/static/custom/css.template src/static/custom/index.css
162 cp -v src/static/custom/css.template src/static/custom/pad.css
163 cp -v src/static/custom/css.template src/static/custom/timeslider.css
164
165 sed -i 's/var\/dirty.db/\/var\/lib\/etherpad-lite\/dirty.db/g' \
166 settings.json.template
167
168 mkdir -v node_modules
169 ln -s ../src node_modules/ep_etherpad-lite
170
171 node bin/doc/generate doc/index.md --format=html \
172 --template=doc/template.html > documentation.html
173
174 cd src
175 npm install
176 cd ..
177 ${builtins.concatStringsSep "\n"
178 (map (n: "npm install ${n}; touch node_modules/${n}/.ep_initialized") etherpad_modules)}
179 '';
180 installPhase = ''
181 mkdir -p $out
182 install -t $out/src/ -vDm 644 src/.ep_initialized
183 cp -a node_modules $out/
184 cp -a src/* $out/src/
32c84ff8
IB
185 ln -sf /var/secrets/webapps/tools-etherpad-sessionkey $out/SESSIONKEY.txt
186 ln -sf /var/secrets/webapps/tools-etherpad-apikey $out/APIKEY.txt
17146204
IB
187 cp ${jquery} $out/src/static/js/jquery.js
188
189 mkdir $out/doc
190 install -t "$out/doc/" \
191 -vDm 644 {CHANGELOG,CONTRIBUTING,README}.md \
192 -vDm 644 documentation.html
193 '';
194 buildInputs = [ pkgs.nodejs pkgs.python ];
195 });
196in
197 {
51900e34 198 inherit webappDir keys listenPort;
17146204 199 }