{ config, pkgs, serverInfo, ... }: with pkgs.lib; let src_clean_skin = pkgs.fetchurl { url = "http://lastlog.de/misc/clean-1.01.tar.gz"; sha256 = "5fb1736b64b33ca3429d035f1358cf8217da2d02019d8a80b14c7985367f659f"; }; src_nixos_skin = pkgs.fetchurl { url = "http://lastlog.de/misc/nixos-1.0.tar.gz"; sha256 = "413b0f451bde81ac2dd0bede17dd088f9abcd0f3cea1722279311ca648a855cf"; }; mediawikiConfig = pkgs.writeText "LocalSettings.php" '' ''; # Unpack Mediawiki and put the config file in its root directory. mediawikiRoot = pkgs.stdenv.mkDerivation rec { name= "mediawiki-1.15.5"; src = pkgs.fetchurl { url = "http://download.wikimedia.org/mediawiki/1.15/${name}.tar.gz"; sha256 = "1d8afbdh3lsg54b69mnh6a47psb3lg978xpp277qs08yz15cjf7q"; }; skinTarball = if config.defaultSkin == "clean" then src_clean_skin else if config.defaultSkin == "nixos" then src_nixos_skin else ""; buildPhase = " if [ '${skinTarball}' ]; then tar xfz ${skinTarball} -C skins/; fi "; installPhase = '' ensureDir $out cp -r * $out cp ${mediawikiConfig} $out/LocalSettings.php ''; }; mediawikiScripts = pkgs.runCommand "mediawiki-${config.id}-scripts" { buildInputs = [ pkgs.makeWrapper ]; } '' ensureDir $out/bin for i in changePassword.php createAndPromote.php userOptions.php edit.php nukePage.php; do makeWrapper ${pkgs.php}/bin/php $out/bin/mediawiki-${config.id}-$(basename $i .php) \ --add-flags ${mediawikiRoot}/maintenance/$i done ''; in { extraConfig = '' ${optionalString config.enableUploads '' Alias ${config.urlPrefix}/images ${config.uploadDir} Order allow,deny Allow from all Options -Indexes ''} Alias ${config.urlPrefix} ${mediawikiRoot} Order allow,deny Allow from all DirectoryIndex index.php ${optionalString (config.articleUrlPrefix != "") '' Alias ${config.articleUrlPrefix} ${mediawikiRoot}/index.php ''} ''; enablePHP = true; options = { id = mkOption { default = "main"; description = '' A unique identifier necessary to keep multiple MediaWiki server instances on the same machine apart. This is used to disambiguate the administrative scripts, which get names like mediawiki-$id-change-password. ''; }; dbType = mkOption { default = "postgres"; example = "mysql"; description = "Database type."; }; dbName = mkOption { default = "mediawiki"; description = "Name of the database that holds the MediaWiki data."; }; dbServer = mkOption { default = ""; # use a Unix domain socket example = "10.0.2.2"; description = '' The location of the database server. Leave empty to use a database server running on the same machine through a Unix domain socket. ''; }; dbUser = mkOption { default = "mediawiki"; description = "The user name for accessing the database."; }; dbPassword = mkOption { default = ""; example = "foobar"; description = '' The password of the database user. Warning: this is stored in cleartext in the Nix store! ''; }; emergencyContact = mkOption { default = serverInfo.serverConfig.adminAddr; example = "admin@example.com"; description = '' Emergency contact e-mail address. Defaults to the Apache admin address. ''; }; passwordSender = mkOption { default = serverInfo.serverConfig.adminAddr; example = "password@example.com"; 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. ''; }; articleUrlPrefix = mkOption { default = "/wiki"; example = ""; description = '' The URL prefix under which article pages appear, e.g. http://server/wiki/Page. Leave empty to use the main URL prefix, e.g. http://server/w/index.php?title=Page. ''; }; enableUploads = mkOption { default = false; description = "Whether to enable file uploads."; }; uploadDir = mkOption { default = throw "You must specify `uploadDir'."; example = "/data/mediawiki-upload"; description = "The directory that stores uploaded files."; }; defaultSkin = mkOption { default = ""; example = "nostalgia"; description = "Set this value to change the default skin used by MediaWiki."; }; extraConfig = mkOption { 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 . ''; }; }; extraPath = [ mediawikiScripts ]; # !!! Need to specify that Apache has a dependency on PostgreSQL! startupScript = pkgs.writeScript "mediawiki_startup.sh" # Initialise the database automagically if we're using a Postgres # server on localhost. (optionalString (config.dbType == "postgres" && config.dbServer == "") '' if ! ${pkgs.postgresql}/bin/psql -l | grep -q ' ${config.dbName} ' ; then ${pkgs.postgresql}/bin/createuser --no-superuser --no-createdb --no-createrole "${config.dbUser}" || true ${pkgs.postgresql}/bin/createdb "${config.dbName}" -O "${config.dbUser}" ( echo 'CREATE LANGUAGE plpgsql;' cat ${mediawikiRoot}/maintenance/postgres/tables.sql echo 'CREATE TEXT SEARCH CONFIGURATION public.default ( COPY = pg_catalog.english );' echo COMMIT ) | ${pkgs.postgresql}/bin/psql -U "${config.dbUser}" "${config.dbName}" fi ''); robotsEntries = optionalString (config.articleUrlPrefix != "") '' User-agent: * Disallow: ${config.urlPrefix}/ Disallow: ${config.articleUrlPrefix}/Special:Search Disallow: ${config.articleUrlPrefix}/Special:Random ''; }