-
Notifications
You must be signed in to change notification settings - Fork 26
/
default.nix
277 lines (239 loc) · 9.33 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
{ config, lib, pkgs, wsName, mkUniqueUser, apache, ... }:
# BUG: if you get this error message when visiting the wiki:
# [320cfa14bce5375c4e8daf65] 2017-03-20 16:17:44: Fatal exception of type MWException
# simply remove this file:
# rm /tmp/l10n_cache-en.cdb
with lib;
{
options = {
emergencyContact = mkOption {
default = "asdf"; # FIXME: need to add correct value
example = "[email protected]";
description = ''
Emergency contact e-mail address. Defaults to the Apache
admin address.
'';
};
passwordSender = mkOption {
default = "asdf"; # FIXME: need to add correct value
example = "[email protected]";
description = ''
E-mail address from which password confirmations originate.
Defaults to the Apache admin address.
'';
};
siteName = mkOption {
default = "MediaWiki";
example = "Foobar Wiki";
description = "Name of the wiki";
};
logo = mkOption {
default = "";
example = "/images/logo.png";
description = "The URL of the site's logo (which should be a 135x135px image).";
};
urlPrefix = mkOption {
default = "/w";
description = ''
The URL prefix under which the Mediawiki service appears. Currently we prepend the `proxyOptions.path` before it so the reverse proxy knows where to route the requests.
'';
};
enableUploads = mkOption {
default = false;
description = "Whether to enable file uploads.";
};
uploadDir = mkOption {
default = "You must specify `uploadDir`.";
example = "/data/mediawiki-upload";
description = "The directory that stores uploaded files.";
};
defaultSkin = mkOption {
default = "Vector";
example = "nostalgia";
description = "Set this value to change the default skin used by MediaWiki.";
};
skins = mkOption {
default = [];
type = types.listOf types.path;
description =
''
List of paths whose content is copied to the ‘skins’
subdirectory of the MediaWiki installation.
'';
};
extraConfig = mkOption {
type = types.lines;
default = "";
example =
''
$wgEnableEmail = false;
'';
description = ''
Any additional text to be appended to MediaWiki's
configuration file. This is a PHP script. For configuration
settings, see <link xlink:href='http://www.mediawiki.org/wiki/Manual:Configuration_settings'/>.
''; #'
};
};
config = let
mediawikiConfig = pkgs.writeText "LocalSettings.php"
''
<?php
# Copied verbatim from the default (generated) LocalSettings.php.
if( defined( 'MW_INSTALL_PATH' ) ) {
$IP = MW_INSTALL_PATH;
} else {
$IP = dirname( __FILE__ );
}
$path = array( $IP, "$IP/includes", "$IP/languages" );
set_include_path( implode( PATH_SEPARATOR, $path ) . PATH_SEPARATOR . get_include_path() );
require_once( "$IP/includes/DefaultSettings.php" );
if ( $wgCommandLineMode ) {
if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
die( "This script must be run from the command line\n" );
}
}
${if config.proxyOptions.path == "/" then ''
$wgScriptPath = "${config.urlPrefix}";
'' else ''
$wgScriptPath = "${config.proxyOptions.path}${config.urlPrefix}";
''}
# BUG SECURITY: needs to be taken care of
# We probably need to set $wgSecretKey and $wgCacheEpoch.
# Paths to external programs.
$wgDiff3 = "${pkgs.diffutils}/bin/diff3";
$wgDiff = "${pkgs.diffutils}/bin/diff";
$wgImageMagickConvertCommand = "${pkgs.imagemagick.out}/bin/convert";
#$wgDebugLogFile = "/tmp/mediawiki_debug_log.txt";
# Database configuration
$wgDBtype = "${if config.defaultDatabaseType == "postgresql"
then "postgres"
else config.defaultDatabaseType}";
$wgDBserver = "${config.database.mediawiki.phpHostname}";
$wgDBuser = "${mkUniqueUser config.database.mediawiki.user}";
$wgDBpassword = "";
$wgDBname = "mediawiki";
# E-mail
$wgEmergencyContact = "${config.emergencyContact}";
$wgPasswordSender = "${config.passwordSender}";
$wgSitename = "${config.siteName}";
# FIXME: make this optiona and auto-remove /tmp/l10n_cache-en.cdb often
wfLoadSkin( 'CologneBlue' );
wfLoadSkin( 'Modern' );
wfLoadSkin( 'MonoBook' );
wfLoadSkin( 'Vector' );
${optionalString (config.logo != "") ''
$wgLogo = "${config.logo}";
''}
# $wgArticlePath = '/$1';
${if config.proxyOptions.path == "/" then ''
'' else ''
$wgArticlePath = "${config.proxyOptions.path}/$1";
''}
${optionalString config.enableUploads ''
$wgEnableUploads = true;
$wgUploadDirectory = "${config.uploadDir}";
''}
${optionalString (config.defaultSkin != "") ''
$wgDefaultSkin = "${config.defaultSkin}";
''}
${config.extraConfig}
#$wgShowExceptionDetails = true;
?>
'';
# Unpack Mediawiki and put the config file in its root directory.
mediawikiRoot = pkgs.stdenv.mkDerivation rec {
name= "mediawiki-1.27.1"; # 1.29.0 – 2017-07-13
src = pkgs.fetchurl {
url = "http://download.wikimedia.org/mediawiki/1.27/${name}.tar.gz";
sha256 = "0sm3ymz93qragbwhzzbwq7f127mbj29inv0afg2z6p32jb1pd9h8";
};
skins = config.skins;
buildPhase =
''
for skin in $skins; do
cp -prvd $skin/* skins/
done
'';
installPhase =
''
mkdir -p $out
cp -r * $out
cp ${mediawikiConfig} $out/LocalSettings.php
sed -i \
-e 's|/bin/bash|${pkgs.bash}/bin/bash|g' \
-e 's|/usr/bin/timeout|${pkgs.coreutils}/bin/timeout|g' \
$out/includes/limit.sh \
$out/includes/GlobalFunctions.php
'';
};
mediawikiScripts = pkgs.runCommand "mediawiki-${config.uniqueName}1-scripts"
{ buildInputs = [ pkgs.makeWrapper ]; }
''
mkdir -p $out/bin
for i in changePassword.php createAndPromote.php userOptions.php edit.php nukePage.php update.php; do
makeWrapper ${config.webserver.apache.phpPackage}/bin/php $out/bin/mediawiki-${config.uniqueName}-$(basename $i .php) \
--add-flags ${mediawikiRoot}/maintenance/$i
done
'';
in rec {
webserver.variant = "apache";
webserver.systemPackages = [ mediawikiScripts ];
# BUG: need to fix /images with URL rewriting
# BUG: need to write proper RewriteRule rule for "/" hosting -> url is borken
# -> http://localhost:60000/w/index.php/Main_Page
# should be
# -> http://localhost:60000/index.php/Main_Page
#
# for config.proxyOptions.path != "/" it works, why?
# -> http://localhost:60000/dd/Main_Page
webserver.apache.extraConfig = ''
${optionalString config.enableUploads ''
Alias ${config.proxyOptions.path}${config.urlPrefix}/images ${config.uploadDir}
<Directory ${config.uploadDir}>
${apache.allGranted}
Options -Indexes
</Directory>
''}
Alias ${builtins.toPath "${config.proxyOptions.path}${config.urlPrefix}"} ${mediawikiRoot}
Alias ${config.proxyOptions.path} ${mediawikiRoot}/index.php
<Directory ${mediawikiRoot}>
${apache.allGranted}
DirectoryIndex index.php
AllowOverride none
</Directory>
'';
webserver.apache.enablePHP = true;
database.mediawiki.user = config.webserver.user;
database.mediawiki.postCreate = let
inherit (config.database.mediawiki) type;
in if type == "postgresql" then ''
( echo 'CREATE LANGUAGE plpgsql;'
cat ${mediawikiRoot}/maintenance/postgres/tables.sql
echo 'CREATE TEXT SEARCH CONFIGURATION public.default ( COPY = pg_catalog.english );'
echo COMMIT
) | sqlsh
'' else if type == "mysql" then ''
sqlsh < ${mediawikiRoot}/maintenance/tables.sql
'' else throw "Unsupported database type `${type}' for MediaWiki.";
# BUG postgresql users must have limited rights, check the rights each start and complain if they don't match!
webserver.startupScript = ''
${config.webserver.apache.phpPackage}/bin/php ${mediawikiRoot}/maintenance/update.php
'';
# BUG: probably broken for config.proxyOptions.path == "/"
webserver.apache.robotsEntries = optionalString (config.proxyOptions.path != "")
''
User-agent: *
Disallow: ${config.proxyOptions.path}${config.urlPrefix}/
Disallow: ${config.proxyOptions.path}/Special:Search
Disallow: ${config.proxyOptions.path}/Special:Random
'';
tests.wanted = [ ./test.nix ];
};
meta = {
description = "A wiki package written in PHP, originally for use on Wikipedia";
maintainers = with maintainers; [ qknight ];
license = licenses.gpl2;
homepage = https://www.mediawiki.org/wiki/MediaWiki;
};
}