]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - virtual/modules/websites/tools/ether/etherpad_lite.nix
Add etherpad lite tool
[perso/Immae/Config/Nix.git] / virtual / modules / websites / tools / ether / etherpad_lite.nix
1 { env, fetchedGithub, fetchurl, stdenv, writeText, pkgs, cacert }:
2 let
3 listenPort = "18001";
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 ];
33 config =
34 # Make sure we’re not rebuilding whole libreoffice just because of a
35 # dependency
36 let libreoffice = (import <nixpkgs> {}).libreoffice-fresh;
37 in
38 writeText "settings.json" ''
39 {
40 "title": "Etherpad",
41 "favicon": "favicon.ico",
42
43 "ip": "127.0.0.1",
44 "port" : ${listenPort},
45 "showSettingsInAdminPage" : false,
46 "dbType" : "postgres",
47 "dbSettings" : {
48 "user" : "${env.postgresql.user}",
49 "host" : "${env.postgresql.socket}",
50 "password": "${env.postgresql.password}",
51 "database": "${env.postgresql.database}",
52 "charset" : "utf8mb4"
53 },
54
55 "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",
56 "padOptions": {
57 "noColors": false,
58 "showControls": true,
59 "showChat": true,
60 "showLineNumbers": true,
61 "useMonospaceFont": false,
62 "userName": false,
63 "userColor": false,
64 "rtl": false,
65 "alwaysShowChat": false,
66 "chatAndUsers": false,
67 "lang": "en-gb"
68 },
69
70 "suppressErrorsInPadText" : false,
71 "requireSession" : false,
72 "editOnly" : false,
73 "sessionNoPassword" : false,
74 "minify" : true,
75 "maxAge" : 21600,
76 "abiword" : null,
77 "soffice" : "${libreoffice}/bin/soffice",
78 "tidyHtml" : "${pkgs.html-tidy}/bin/tidy",
79 "allowUnknownFileEnds" : true,
80 "requireAuthentication" : false,
81 "requireAuthorization" : false,
82 "trustProxy" : false,
83 "disableIPlogging" : false,
84 "automaticReconnectionTimeout" : 0,
85 "scrollWhenFocusLineIsOutOfViewport": {
86 "percentage": {
87 "editionAboveViewport": 0,
88 "editionBelowViewport": 0
89 },
90 "duration": 0,
91 "scrollWhenCaretIsInTheLastLineOfViewport": false,
92 "percentageToScrollWhenUserPressesArrowUp": 0
93 },
94 "users": {
95 "ldapauth": {
96 "url": "ldaps://${env.ldap.host}",
97 "accountBase": "${env.ldap.base}",
98 "accountPattern": "(&(memberOf=cn=users,cn=etherpad,ou=services,dc=immae,dc=eu)(uid={{username}}))",
99 "displayNameAttribute": "cn",
100 "searchDN": "cn=etherpad,ou=services,dc=immae,dc=eu",
101 "searchPWD": "${env.ldap.password}",
102 "groupSearchBase": "${env.ldap.base}",
103 "groupAttribute": "member",
104 "groupAttributeIsDN": true,
105 "searchScope": "sub",
106 "groupSearch": "(memberOf=cn=groups,cn=etherpad,ou=services,dc=immae,dc=eu)",
107 "anonymousReadonly": false
108 }
109 },
110 "socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],
111 "loadTest": false,
112 "indentationOnNewLine": false,
113 "toolbar": {
114 "left": [
115 ["bold", "italic", "underline", "strikethrough"],
116 ["orderedlist", "unorderedlist", "indent", "outdent"],
117 ["undo", "redo"],
118 ["clearauthorship"]
119 ],
120 "right": [
121 ["importexport", "timeslider", "savedrevision"],
122 ["settings", "embed"],
123 ["showusers"]
124 ],
125 "timeslider": [
126 ["timeslider_export", "timeslider_returnToPad"]
127 ]
128 },
129 "loglevel": "INFO",
130 "logconfig" : { "appenders": [ { "type": "console" } ] }
131 }
132 '';
133 webappDir = stdenv.mkDerivation (fetchedGithub ./etherpad-lite.json // rec {
134 __noChroot = true;
135 patches = [ ./libreoffice_patch.diff ];
136 buildPhase = ''
137 export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
138 export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
139 export HOME=$PWD
140
141 touch src/.ep_initialized
142 cp -v src/static/custom/js.template src/static/custom/index.js
143 cp -v src/static/custom/js.template src/static/custom/pad.js
144 cp -v src/static/custom/js.template src/static/custom/timeslider.js
145 cp -v src/static/custom/css.template src/static/custom/index.css
146 cp -v src/static/custom/css.template src/static/custom/pad.css
147 cp -v src/static/custom/css.template src/static/custom/timeslider.css
148
149 sed -i 's/var\/dirty.db/\/var\/lib\/etherpad-lite\/dirty.db/g' \
150 settings.json.template
151
152 mkdir -v node_modules
153 ln -s ../src node_modules/ep_etherpad-lite
154
155 node bin/doc/generate doc/index.md --format=html \
156 --template=doc/template.html > documentation.html
157
158 cd src
159 npm install
160 cd ..
161 ${builtins.concatStringsSep "\n"
162 (map (n: "npm install ${n}; touch node_modules/${n}/.ep_initialized") etherpad_modules)}
163 '';
164 installPhase = ''
165 mkdir -p $out
166 install -t $out/src/ -vDm 644 src/.ep_initialized
167 cp -a node_modules $out/
168 cp -a src/* $out/src/
169 ln -sf ${sessionkey} $out/SESSIONKEY.txt
170 ln -sf ${apikey} $out/APIKEY.txt
171 cp ${jquery} $out/src/static/js/jquery.js
172
173 mkdir $out/doc
174 install -t "$out/doc/" \
175 -vDm 644 {CHANGELOG,CONTRIBUTING,README}.md \
176 -vDm 644 documentation.html
177 '';
178 buildInputs = [ pkgs.nodejs pkgs.python ];
179 });
180 in
181 {
182 inherit webappDir config listenPort;
183 }