2019-06-06 01:19:11 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
inherit (lib) mkDefault mkEnableOption mkPackageOption mkForce mkIf mkMerge mkOption;
|
2021-10-03 16:06:03 +00:00
|
|
|
inherit (lib) concatStringsSep literalExpression mapAttrsToList optional optionals optionalString types;
|
2019-06-06 01:19:11 +00:00
|
|
|
|
|
|
|
cfg = config.services.mediawiki;
|
|
|
|
fpm = config.services.phpfpm.pools.mediawiki;
|
|
|
|
user = "mediawiki";
|
2023-09-17 22:32:51 +00:00
|
|
|
group =
|
|
|
|
if cfg.webserver == "apache" then
|
|
|
|
config.services.httpd.group
|
|
|
|
else if cfg.webserver == "nginx" then
|
|
|
|
config.services.nginx.group
|
|
|
|
else "mediawiki";
|
2023-04-24 12:21:06 +00:00
|
|
|
|
2019-06-06 01:19:11 +00:00
|
|
|
cacheDir = "/var/cache/mediawiki";
|
|
|
|
stateDir = "/var/lib/mediawiki";
|
|
|
|
|
2024-04-15 20:59:37 +00:00
|
|
|
# https://www.mediawiki.org/wiki/Compatibility
|
|
|
|
php = pkgs.php81;
|
|
|
|
|
2019-06-06 01:19:11 +00:00
|
|
|
pkg = pkgs.stdenv.mkDerivation rec {
|
|
|
|
pname = "mediawiki-full";
|
2023-07-10 22:53:25 +00:00
|
|
|
inherit (src) version;
|
2019-06-06 01:19:11 +00:00
|
|
|
src = cfg.package;
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
|
|
|
cp -r * $out/
|
|
|
|
|
2023-07-10 22:53:25 +00:00
|
|
|
# try removing directories before symlinking to allow overwriting any builtin extension or skin
|
2019-06-06 01:19:11 +00:00
|
|
|
${concatStringsSep "\n" (mapAttrsToList (k: v: ''
|
2023-07-10 22:53:25 +00:00
|
|
|
rm -rf $out/share/mediawiki/skins/${k}
|
2019-06-06 01:19:11 +00:00
|
|
|
ln -s ${v} $out/share/mediawiki/skins/${k}
|
|
|
|
'') cfg.skins)}
|
|
|
|
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList (k: v: ''
|
2023-07-10 22:53:25 +00:00
|
|
|
rm -rf $out/share/mediawiki/extensions/${k}
|
2020-03-26 17:21:43 +00:00
|
|
|
ln -s ${if v != null then v else "$src/share/mediawiki/extensions/${k}"} $out/share/mediawiki/extensions/${k}
|
2019-06-06 01:19:11 +00:00
|
|
|
'') cfg.extensions)}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
mediawikiScripts = pkgs.runCommand "mediawiki-scripts" {
|
2022-09-24 21:28:38 +00:00
|
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
2019-06-06 01:19:11 +00:00
|
|
|
preferLocalBuild = true;
|
|
|
|
} ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
for i in changePassword.php createAndPromote.php userOptions.php edit.php nukePage.php update.php; do
|
2024-04-15 20:59:37 +00:00
|
|
|
makeWrapper ${php}/bin/php $out/bin/mediawiki-$(basename $i .php) \
|
2019-06-06 01:19:11 +00:00
|
|
|
--set MEDIAWIKI_CONFIG ${mediawikiConfig} \
|
|
|
|
--add-flags ${pkg}/share/mediawiki/maintenance/$i
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2023-04-03 15:05:21 +00:00
|
|
|
dbAddr = if cfg.database.socket == null then
|
|
|
|
"${cfg.database.host}:${toString cfg.database.port}"
|
|
|
|
else if cfg.database.type == "mysql" then
|
|
|
|
"${cfg.database.host}:${cfg.database.socket}"
|
|
|
|
else if cfg.database.type == "postgres" then
|
|
|
|
"${cfg.database.socket}"
|
|
|
|
else
|
|
|
|
throw "Unsupported database type: ${cfg.database.type} for socket: ${cfg.database.socket}";
|
|
|
|
|
2019-06-06 01:19:11 +00:00
|
|
|
mediawikiConfig = pkgs.writeText "LocalSettings.php" ''
|
|
|
|
<?php
|
|
|
|
# Protect against web entry
|
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$wgSitename = "${cfg.name}";
|
|
|
|
$wgMetaNamespace = false;
|
|
|
|
|
|
|
|
## The URL base path to the directory containing the wiki;
|
|
|
|
## defaults for all runtime URL paths are based off of this.
|
|
|
|
## For more information on customizing the URLs
|
|
|
|
## (like /w/index.php/Page_title to /wiki/Page_title) please see:
|
|
|
|
## https://www.mediawiki.org/wiki/Manual:Short_URL
|
2023-09-17 22:32:51 +00:00
|
|
|
$wgScriptPath = "${lib.optionalString (cfg.webserver == "nginx") "/w"}";
|
2019-06-06 01:19:11 +00:00
|
|
|
|
|
|
|
## The protocol and server name to use in fully-qualified URLs
|
2023-04-24 12:21:06 +00:00
|
|
|
$wgServer = "${cfg.url}";
|
2019-06-06 01:19:11 +00:00
|
|
|
|
|
|
|
## The URL path to static resources (images, scripts, etc.)
|
|
|
|
$wgResourceBasePath = $wgScriptPath;
|
|
|
|
|
2023-09-17 22:32:51 +00:00
|
|
|
${lib.optionalString (cfg.webserver == "nginx") ''
|
|
|
|
$wgArticlePath = "/wiki/$1";
|
|
|
|
$wgUsePathInfo = true;
|
|
|
|
''}
|
|
|
|
|
2019-06-06 01:19:11 +00:00
|
|
|
## The URL path to the logo. Make sure you change this from the default,
|
|
|
|
## or else you'll overwrite your logo when you upgrade!
|
|
|
|
$wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
|
|
|
|
|
|
|
|
## UPO means: this is also a user preference option
|
|
|
|
|
|
|
|
$wgEnableEmail = true;
|
|
|
|
$wgEnableUserEmail = true; # UPO
|
|
|
|
|
2023-04-24 12:21:06 +00:00
|
|
|
$wgPasswordSender = "${cfg.passwordSender}";
|
2019-06-06 01:19:11 +00:00
|
|
|
|
|
|
|
$wgEnotifUserTalk = false; # UPO
|
|
|
|
$wgEnotifWatchlist = false; # UPO
|
|
|
|
$wgEmailAuthentication = true;
|
|
|
|
|
|
|
|
## Database settings
|
|
|
|
$wgDBtype = "${cfg.database.type}";
|
2023-04-03 15:05:21 +00:00
|
|
|
$wgDBserver = "${dbAddr}";
|
|
|
|
$wgDBport = "${toString cfg.database.port}";
|
2019-06-06 01:19:11 +00:00
|
|
|
$wgDBname = "${cfg.database.name}";
|
|
|
|
$wgDBuser = "${cfg.database.user}";
|
|
|
|
${optionalString (cfg.database.passwordFile != null) "$wgDBpassword = file_get_contents(\"${cfg.database.passwordFile}\");"}
|
|
|
|
|
|
|
|
${optionalString (cfg.database.type == "mysql" && cfg.database.tablePrefix != null) ''
|
|
|
|
# MySQL specific settings
|
|
|
|
$wgDBprefix = "${cfg.database.tablePrefix}";
|
|
|
|
''}
|
|
|
|
|
|
|
|
${optionalString (cfg.database.type == "mysql") ''
|
|
|
|
# MySQL table options to use during installation or update
|
|
|
|
$wgDBTableOptions = "ENGINE=InnoDB, DEFAULT CHARSET=binary";
|
|
|
|
''}
|
|
|
|
|
|
|
|
## Shared memory settings
|
|
|
|
$wgMainCacheType = CACHE_NONE;
|
|
|
|
$wgMemCachedServers = [];
|
|
|
|
|
|
|
|
${optionalString (cfg.uploadsDir != null) ''
|
|
|
|
$wgEnableUploads = true;
|
|
|
|
$wgUploadDirectory = "${cfg.uploadsDir}";
|
|
|
|
''}
|
|
|
|
|
|
|
|
$wgUseImageMagick = true;
|
|
|
|
$wgImageMagickConvertCommand = "${pkgs.imagemagick}/bin/convert";
|
|
|
|
|
|
|
|
# InstantCommons allows wiki to use images from https://commons.wikimedia.org
|
|
|
|
$wgUseInstantCommons = false;
|
|
|
|
|
|
|
|
# Periodically send a pingback to https://www.mediawiki.org/ with basic data
|
|
|
|
# about this MediaWiki instance. The Wikimedia Foundation shares this data
|
|
|
|
# with MediaWiki developers to help guide future development efforts.
|
|
|
|
$wgPingback = true;
|
|
|
|
|
|
|
|
## If you use ImageMagick (or any other shell command) on a
|
|
|
|
## Linux server, this will need to be set to the name of an
|
|
|
|
## available UTF-8 locale
|
|
|
|
$wgShellLocale = "C.UTF-8";
|
|
|
|
|
|
|
|
## Set $wgCacheDirectory to a writable directory on the web server
|
|
|
|
## to make your wiki go slightly faster. The directory should not
|
2022-12-18 00:31:14 +00:00
|
|
|
## be publicly accessible from the web.
|
2019-06-06 01:19:11 +00:00
|
|
|
$wgCacheDirectory = "${cacheDir}";
|
|
|
|
|
|
|
|
# Site language code, should be one of the list in ./languages/data/Names.php
|
|
|
|
$wgLanguageCode = "en";
|
|
|
|
|
|
|
|
$wgSecretKey = file_get_contents("${stateDir}/secret.key");
|
|
|
|
|
|
|
|
# Changing this will log out all existing sessions.
|
|
|
|
$wgAuthenticationTokenVersion = "";
|
|
|
|
|
|
|
|
## For attaching licensing metadata to pages, and displaying an
|
|
|
|
## appropriate copyright notice / icon. GNU Free Documentation
|
|
|
|
## License and Creative Commons licenses are supported so far.
|
|
|
|
$wgRightsPage = ""; # Set to the title of a wiki page that describes your license/copyright
|
|
|
|
$wgRightsUrl = "";
|
|
|
|
$wgRightsText = "";
|
|
|
|
$wgRightsIcon = "";
|
|
|
|
|
|
|
|
# Path to the GNU diff3 utility. Used for conflict resolution.
|
|
|
|
$wgDiff = "${pkgs.diffutils}/bin/diff";
|
|
|
|
$wgDiff3 = "${pkgs.diffutils}/bin/diff3";
|
|
|
|
|
|
|
|
# Enabled skins.
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList (k: v: "wfLoadSkin('${k}');") cfg.skins)}
|
|
|
|
|
|
|
|
# Enabled extensions.
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList (k: v: "wfLoadExtension('${k}');") cfg.extensions)}
|
|
|
|
|
|
|
|
|
|
|
|
# End of automatically generated settings.
|
|
|
|
# Add more configuration options below.
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
2023-09-17 22:32:51 +00:00
|
|
|
withTrailingSlash = str: if lib.hasSuffix "/" str then str else "${str}/";
|
2019-06-06 01:19:11 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
# interface
|
|
|
|
options = {
|
|
|
|
services.mediawiki = {
|
|
|
|
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "MediaWiki";
|
2019-06-06 01:19:11 +00:00
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
package = mkPackageOption pkgs "mediawiki" { };
|
2019-06-06 01:19:11 +00:00
|
|
|
|
2023-04-28 21:05:55 +00:00
|
|
|
finalPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
readOnly = true;
|
|
|
|
default = pkg;
|
|
|
|
defaultText = literalExpression "pkg";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2023-04-28 21:05:55 +00:00
|
|
|
The final package used by the module. This is the package that will have extensions and skins installed.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-06-06 01:19:11 +00:00
|
|
|
name = mkOption {
|
2021-01-31 10:28:04 +00:00
|
|
|
type = types.str;
|
2019-06-06 01:19:11 +00:00
|
|
|
default = "MediaWiki";
|
|
|
|
example = "Foobar Wiki";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Name of the wiki.";
|
2019-06-06 01:19:11 +00:00
|
|
|
};
|
|
|
|
|
2023-04-24 12:21:06 +00:00
|
|
|
url = mkOption {
|
|
|
|
type = types.str;
|
2023-09-17 22:32:51 +00:00
|
|
|
default =
|
|
|
|
if cfg.webserver == "apache" then
|
2023-04-24 12:21:06 +00:00
|
|
|
"${if cfg.httpd.virtualHost.addSSL || cfg.httpd.virtualHost.forceSSL || cfg.httpd.virtualHost.onlySSL then "https" else "http"}://${cfg.httpd.virtualHost.hostName}"
|
2023-09-17 22:32:51 +00:00
|
|
|
else if cfg.webserver == "nginx" then
|
|
|
|
let
|
|
|
|
hasSSL = host: host.forceSSL || host.addSSL;
|
|
|
|
in
|
|
|
|
"${if hasSSL config.services.nginx.virtualHosts.${cfg.nginx.hostName} then "https" else "http"}://${cfg.nginx.hostName}"
|
2023-04-24 12:21:06 +00:00
|
|
|
else
|
|
|
|
"http://localhost";
|
2023-11-23 10:35:47 +00:00
|
|
|
defaultText = ''
|
|
|
|
if "mediawiki uses ssl" then "{"https" else "http"}://''${cfg.hostName}" else "http://localhost";
|
2023-04-24 12:21:06 +00:00
|
|
|
'';
|
|
|
|
example = "https://wiki.example.org";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "URL of the wiki.";
|
2023-04-24 12:21:06 +00:00
|
|
|
};
|
|
|
|
|
2019-06-06 01:19:11 +00:00
|
|
|
uploadsDir = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = "${stateDir}/uploads";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2019-06-06 01:19:11 +00:00
|
|
|
This directory is used for uploads of pictures. The directory passed here is automatically
|
|
|
|
created and permissions adjusted as required.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.path;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "A file containing the initial password for the admin user.";
|
2019-06-06 01:19:11 +00:00
|
|
|
example = "/run/keys/mediawiki-password";
|
|
|
|
};
|
|
|
|
|
2023-04-24 12:21:06 +00:00
|
|
|
passwordSender = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default =
|
|
|
|
if cfg.webserver == "apache" then
|
|
|
|
if cfg.httpd.virtualHost.adminAddr != null then
|
|
|
|
cfg.httpd.virtualHost.adminAddr
|
|
|
|
else
|
|
|
|
config.services.httpd.adminAddr else "root@localhost";
|
|
|
|
defaultText = literalExpression ''
|
|
|
|
if cfg.webserver == "apache" then
|
|
|
|
if cfg.httpd.virtualHost.adminAddr != null then
|
|
|
|
cfg.httpd.virtualHost.adminAddr
|
|
|
|
else
|
|
|
|
config.services.httpd.adminAddr else "root@localhost"
|
|
|
|
'';
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Contact address for password reset.";
|
2023-04-24 12:21:06 +00:00
|
|
|
};
|
|
|
|
|
2019-06-06 01:19:11 +00:00
|
|
|
skins = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.attrsOf types.path;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2020-03-26 17:21:43 +00:00
|
|
|
Attribute set of paths whose content is copied to the {file}`skins`
|
|
|
|
subdirectory of the MediaWiki installation in addition to the default skins.
|
2019-06-06 01:19:11 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extensions = mkOption {
|
|
|
|
default = {};
|
2020-03-26 17:21:43 +00:00
|
|
|
type = types.attrsOf (types.nullOr types.path);
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2020-03-26 17:21:43 +00:00
|
|
|
Attribute set of paths whose content is copied to the {file}`extensions`
|
|
|
|
subdirectory of the MediaWiki installation and enabled in configuration.
|
|
|
|
|
|
|
|
Use `null` instead of path to enable extensions that are part of MediaWiki.
|
|
|
|
'';
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2020-03-26 17:21:43 +00:00
|
|
|
{
|
|
|
|
Matomo = pkgs.fetchzip {
|
|
|
|
url = "https://github.com/DaSchTour/matomo-mediawiki-extension/archive/v4.0.1.tar.gz";
|
|
|
|
sha256 = "0g5rd3zp0avwlmqagc59cg9bbkn3r7wx7p6yr80s644mj6dlvs1b";
|
|
|
|
};
|
|
|
|
ParserFunctions = null;
|
|
|
|
}
|
2019-06-06 01:19:11 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-04-24 12:21:06 +00:00
|
|
|
webserver = mkOption {
|
2023-09-17 22:32:51 +00:00
|
|
|
type = types.enum [ "apache" "none" "nginx" ];
|
2023-04-24 12:21:06 +00:00
|
|
|
default = "apache";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Webserver to use.";
|
2023-04-24 12:21:06 +00:00
|
|
|
};
|
|
|
|
|
2019-06-06 01:19:11 +00:00
|
|
|
database = {
|
|
|
|
type = mkOption {
|
2023-11-11 14:33:19 +00:00
|
|
|
type = types.enum [ "mysql" "postgres" "mssql" "oracle" ];
|
2019-06-06 01:19:11 +00:00
|
|
|
default = "mysql";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Database engine to use. MySQL/MariaDB is the database of choice by MediaWiki developers.";
|
2019-06-06 01:19:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Database host address.";
|
2019-06-06 01:19:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
2023-04-03 15:05:21 +00:00
|
|
|
default = if cfg.database.type == "mysql" then 3306 else 5432;
|
|
|
|
defaultText = literalExpression "3306";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Database host port.";
|
2019-06-06 01:19:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "mediawiki";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Database name.";
|
2019-06-06 01:19:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "mediawiki";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Database user.";
|
2019-06-06 01:19:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
example = "/run/keys/mediawiki-dbpassword";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2019-06-06 01:19:11 +00:00
|
|
|
A file containing the password corresponding to
|
|
|
|
{option}`database.user`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tablePrefix = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2019-06-06 01:19:11 +00:00
|
|
|
If you only have access to a single database and wish to install more than
|
|
|
|
one version of MediaWiki, or have other applications that also use the
|
|
|
|
database, you can give the table names a unique prefix to stop any naming
|
|
|
|
conflicts or confusion.
|
|
|
|
See <https://www.mediawiki.org/wiki/Manual:$wgDBprefix>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
socket = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
2023-04-03 15:05:21 +00:00
|
|
|
default = if (cfg.database.type == "mysql" && cfg.database.createLocally) then
|
|
|
|
"/run/mysqld/mysqld.sock"
|
|
|
|
else if (cfg.database.type == "postgres" && cfg.database.createLocally) then
|
|
|
|
"/run/postgresql"
|
|
|
|
else
|
|
|
|
null;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "/run/mysqld/mysqld.sock";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Path to the unix socket file to use for authentication.";
|
2019-06-06 01:19:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
createLocally = mkOption {
|
|
|
|
type = types.bool;
|
2023-04-03 15:05:21 +00:00
|
|
|
default = cfg.database.type == "mysql" || cfg.database.type == "postgres";
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "true";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2019-06-06 01:19:11 +00:00
|
|
|
Create the database and database user locally.
|
|
|
|
This currently only applies if database type "mysql" is selected.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-09-17 22:32:51 +00:00
|
|
|
nginx.hostName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = literalExpression ''wiki.example.com'';
|
|
|
|
default = "localhost";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2023-09-17 22:32:51 +00:00
|
|
|
The hostname to use for the nginx virtual host.
|
|
|
|
This is used to generate the nginx configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-04-24 10:43:06 +00:00
|
|
|
httpd.virtualHost = mkOption {
|
2020-01-25 01:36:48 +00:00
|
|
|
type = types.submodule (import ../web-servers/apache-httpd/vhost-options.nix);
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2019-06-06 01:19:11 +00:00
|
|
|
{
|
|
|
|
hostName = "mediawiki.example.org";
|
|
|
|
adminAddr = "webmaster@example.org";
|
2019-11-04 21:24:55 +00:00
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
2019-06-06 01:19:11 +00:00
|
|
|
}
|
|
|
|
'';
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2019-06-06 01:19:11 +00:00
|
|
|
Apache configuration can be done by adapting {option}`services.httpd.virtualHosts`.
|
|
|
|
See [](#opt-services.httpd.virtualHosts) for further information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
poolConfig = mkOption {
|
2019-08-08 02:36:49 +00:00
|
|
|
type = with types; attrsOf (oneOf [ str int bool ]);
|
|
|
|
default = {
|
|
|
|
"pm" = "dynamic";
|
|
|
|
"pm.max_children" = 32;
|
|
|
|
"pm.start_servers" = 2;
|
|
|
|
"pm.min_spare_servers" = 2;
|
|
|
|
"pm.max_spare_servers" = 4;
|
|
|
|
"pm.max_requests" = 500;
|
|
|
|
};
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2019-08-08 02:36:49 +00:00
|
|
|
Options for the MediaWiki PHP pool. See the documentation on `php-fpm.conf`
|
2019-06-06 01:19:11 +00:00
|
|
|
for details on configuration directives.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2019-06-06 01:19:11 +00:00
|
|
|
Any additional text to be appended to MediaWiki's
|
|
|
|
LocalSettings.php configuration file. For configuration
|
|
|
|
settings, see <https://www.mediawiki.org/wiki/Manual:Configuration_settings>.
|
|
|
|
'';
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
$wgEnableEmail = false;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-04-24 10:43:06 +00:00
|
|
|
imports = [
|
|
|
|
(lib.mkRenamedOptionModule [ "services" "mediawiki" "virtualHost" ] [ "services" "mediawiki" "httpd" "virtualHost" ])
|
|
|
|
];
|
|
|
|
|
2019-06-06 01:19:11 +00:00
|
|
|
# implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
assertions = [
|
2023-04-03 15:05:21 +00:00
|
|
|
{ assertion = cfg.database.createLocally -> (cfg.database.type == "mysql" || cfg.database.type == "postgres");
|
|
|
|
message = "services.mediawiki.createLocally is currently only supported for database type 'mysql' and 'postgres'";
|
2019-06-06 01:19:11 +00:00
|
|
|
}
|
nixos/postgresql: drop ensurePermissions, fix ensureUsers for postgresql15
Closes #216989
First of all, a bit of context: in PostgreSQL, newly created users don't
have the CREATE privilege on the public schema of a database even with
`ALL PRIVILEGES` granted via `ensurePermissions` which is how most of
the DB users are currently set up "declaratively"[1]. This means e.g. a
freshly deployed Nextcloud service will break early because Nextcloud
itself cannot CREATE any tables in the public schema anymore.
The other issue here is that `ensurePermissions` is a mere hack. It's
effectively a mixture of SQL code (e.g. `DATABASE foo` is relying on how
a value is substituted in a query. You'd have to parse a subset of SQL
to actually know which object are permissions granted to for a user).
After analyzing the existing modules I realized that in every case with
a single exception[2] the UNIX system user is equal to the db user is
equal to the db name and I don't see a compelling reason why people
would change that in 99% of the cases. In fact, some modules would even
break if you'd change that because the declarations of the system user &
the db user are mixed up[3].
So I decided to go with something new which restricts the ways to use
`ensure*` options rather than expanding those[4]. Effectively this means
that
* The DB user _must_ be equal to the DB name.
* Permissions are granted via `ensureDBOwnerhip` for an attribute-set in
`ensureUsers`. That way, the user is actually the owner and can
perform `CREATE`.
* For such a postgres user, a database must be declared in
`ensureDatabases`.
For anything else, a custom state management should be implemented. This
can either be `initialScript`, doing it manual, outside of the module or
by implementing proper state management for postgresql[5], but the
current state of `ensure*` isn't even declarative, but a convergent tool
which is what Nix actually claims to _not_ do.
Regarding existing setups: there are effectively two options:
* Leave everything as-is (assuming that system user == db user == db
name): then the DB user will automatically become the DB owner and
everything else stays the same.
* Drop the `createDatabase = true;` declarations: nothing will change
because a removal of `ensure*` statements is ignored, so it doesn't
matter at all whether this option is kept after the first deploy (and
later on you'd usually restore from backups anyways).
The DB user isn't the owner of the DB then, but for an existing setup
this is irrelevant because CREATE on the public schema isn't revoked
from existing users (only not granted for new users).
[1] not really declarative though because removals of these statements
are simply ignored for instance: https://github.com/NixOS/nixpkgs/issues/206467
[2] `services.invidious`: I removed the `ensure*` part temporarily
because it IMHO falls into the category "manage the state on your
own" (see the commit message). See also
https://github.com/NixOS/nixpkgs/pull/265857
[3] e.g. roundcube had `"DATABASE ${cfg.database.username}" = "ALL PRIVILEGES";`
[4] As opposed to other changes that are considered a potential fix, but
also add more things like collation for DBs or passwords that are
_never_ touched again when changing those.
[5] As suggested in e.g. https://github.com/NixOS/nixpkgs/issues/206467
2023-11-08 11:50:09 +00:00
|
|
|
{ assertion = cfg.database.createLocally -> cfg.database.user == user && cfg.database.name == cfg.database.user;
|
2019-06-06 01:19:11 +00:00
|
|
|
message = "services.mediawiki.database.user must be set to ${user} if services.mediawiki.database.createLocally is set true";
|
|
|
|
}
|
|
|
|
{ assertion = cfg.database.createLocally -> cfg.database.socket != null;
|
|
|
|
message = "services.mediawiki.database.socket must be set if services.mediawiki.database.createLocally is set to true";
|
|
|
|
}
|
|
|
|
{ assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
|
|
|
|
message = "a password cannot be specified if services.mediawiki.database.createLocally is set to true";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
services.mediawiki.skins = {
|
|
|
|
MonoBook = "${cfg.package}/share/mediawiki/skins/MonoBook";
|
|
|
|
Timeless = "${cfg.package}/share/mediawiki/skins/Timeless";
|
|
|
|
Vector = "${cfg.package}/share/mediawiki/skins/Vector";
|
|
|
|
};
|
|
|
|
|
2023-04-03 15:05:21 +00:00
|
|
|
services.mysql = mkIf (cfg.database.type == "mysql" && cfg.database.createLocally) {
|
2019-06-06 01:19:11 +00:00
|
|
|
enable = true;
|
|
|
|
package = mkDefault pkgs.mariadb;
|
|
|
|
ensureDatabases = [ cfg.database.name ];
|
2023-04-03 15:05:21 +00:00
|
|
|
ensureUsers = [{
|
|
|
|
name = cfg.database.user;
|
|
|
|
ensurePermissions = { "${cfg.database.name}.*" = "ALL PRIVILEGES"; };
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = mkIf (cfg.database.type == "postgres" && cfg.database.createLocally) {
|
|
|
|
enable = true;
|
|
|
|
ensureDatabases = [ cfg.database.name ];
|
|
|
|
ensureUsers = [{
|
|
|
|
name = cfg.database.user;
|
nixos/postgresql: drop ensurePermissions, fix ensureUsers for postgresql15
Closes #216989
First of all, a bit of context: in PostgreSQL, newly created users don't
have the CREATE privilege on the public schema of a database even with
`ALL PRIVILEGES` granted via `ensurePermissions` which is how most of
the DB users are currently set up "declaratively"[1]. This means e.g. a
freshly deployed Nextcloud service will break early because Nextcloud
itself cannot CREATE any tables in the public schema anymore.
The other issue here is that `ensurePermissions` is a mere hack. It's
effectively a mixture of SQL code (e.g. `DATABASE foo` is relying on how
a value is substituted in a query. You'd have to parse a subset of SQL
to actually know which object are permissions granted to for a user).
After analyzing the existing modules I realized that in every case with
a single exception[2] the UNIX system user is equal to the db user is
equal to the db name and I don't see a compelling reason why people
would change that in 99% of the cases. In fact, some modules would even
break if you'd change that because the declarations of the system user &
the db user are mixed up[3].
So I decided to go with something new which restricts the ways to use
`ensure*` options rather than expanding those[4]. Effectively this means
that
* The DB user _must_ be equal to the DB name.
* Permissions are granted via `ensureDBOwnerhip` for an attribute-set in
`ensureUsers`. That way, the user is actually the owner and can
perform `CREATE`.
* For such a postgres user, a database must be declared in
`ensureDatabases`.
For anything else, a custom state management should be implemented. This
can either be `initialScript`, doing it manual, outside of the module or
by implementing proper state management for postgresql[5], but the
current state of `ensure*` isn't even declarative, but a convergent tool
which is what Nix actually claims to _not_ do.
Regarding existing setups: there are effectively two options:
* Leave everything as-is (assuming that system user == db user == db
name): then the DB user will automatically become the DB owner and
everything else stays the same.
* Drop the `createDatabase = true;` declarations: nothing will change
because a removal of `ensure*` statements is ignored, so it doesn't
matter at all whether this option is kept after the first deploy (and
later on you'd usually restore from backups anyways).
The DB user isn't the owner of the DB then, but for an existing setup
this is irrelevant because CREATE on the public schema isn't revoked
from existing users (only not granted for new users).
[1] not really declarative though because removals of these statements
are simply ignored for instance: https://github.com/NixOS/nixpkgs/issues/206467
[2] `services.invidious`: I removed the `ensure*` part temporarily
because it IMHO falls into the category "manage the state on your
own" (see the commit message). See also
https://github.com/NixOS/nixpkgs/pull/265857
[3] e.g. roundcube had `"DATABASE ${cfg.database.username}" = "ALL PRIVILEGES";`
[4] As opposed to other changes that are considered a potential fix, but
also add more things like collation for DBs or passwords that are
_never_ touched again when changing those.
[5] As suggested in e.g. https://github.com/NixOS/nixpkgs/issues/206467
2023-11-08 11:50:09 +00:00
|
|
|
ensureDBOwnership = true;
|
2023-04-03 15:05:21 +00:00
|
|
|
}];
|
2019-06-06 01:19:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.phpfpm.pools.mediawiki = {
|
2019-08-08 02:36:49 +00:00
|
|
|
inherit user group;
|
|
|
|
phpEnv.MEDIAWIKI_CONFIG = "${mediawikiConfig}";
|
2024-04-15 20:59:37 +00:00
|
|
|
phpPackage = php;
|
2023-04-24 12:21:06 +00:00
|
|
|
settings = (if (cfg.webserver == "apache") then {
|
2019-08-08 02:36:49 +00:00
|
|
|
"listen.owner" = config.services.httpd.user;
|
|
|
|
"listen.group" = config.services.httpd.group;
|
2023-09-17 22:32:51 +00:00
|
|
|
} else if (cfg.webserver == "nginx") then {
|
|
|
|
"listen.owner" = config.services.nginx.user;
|
|
|
|
"listen.group" = config.services.nginx.group;
|
2023-04-24 12:21:06 +00:00
|
|
|
} else {
|
|
|
|
"listen.owner" = user;
|
|
|
|
"listen.group" = group;
|
|
|
|
}) // cfg.poolConfig;
|
2019-06-06 01:19:11 +00:00
|
|
|
};
|
|
|
|
|
2023-04-24 12:21:06 +00:00
|
|
|
services.httpd = lib.mkIf (cfg.webserver == "apache") {
|
2019-06-06 01:19:11 +00:00
|
|
|
enable = true;
|
|
|
|
extraModules = [ "proxy_fcgi" ];
|
2023-04-24 12:21:06 +00:00
|
|
|
virtualHosts.${cfg.httpd.virtualHost.hostName} = mkMerge [
|
|
|
|
cfg.httpd.virtualHost
|
|
|
|
{
|
|
|
|
documentRoot = mkForce "${pkg}/share/mediawiki";
|
|
|
|
extraConfig = ''
|
|
|
|
<Directory "${pkg}/share/mediawiki">
|
|
|
|
<FilesMatch "\.php$">
|
|
|
|
<If "-f %{REQUEST_FILENAME}">
|
|
|
|
SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
|
|
|
|
</If>
|
|
|
|
</FilesMatch>
|
|
|
|
|
|
|
|
Require all granted
|
|
|
|
DirectoryIndex index.php
|
|
|
|
AllowOverride All
|
|
|
|
</Directory>
|
|
|
|
'' + optionalString (cfg.uploadsDir != null) ''
|
|
|
|
Alias "/images" "${cfg.uploadsDir}"
|
|
|
|
<Directory "${cfg.uploadsDir}">
|
|
|
|
Require all granted
|
|
|
|
</Directory>
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
2019-06-06 01:19:11 +00:00
|
|
|
};
|
2023-09-17 22:32:51 +00:00
|
|
|
# inspired by https://www.mediawiki.org/wiki/Manual:Short_URL/Nginx
|
|
|
|
services.nginx = lib.mkIf (cfg.webserver == "nginx") {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts.${config.services.mediawiki.nginx.hostName} = {
|
|
|
|
root = "${pkg}/share/mediawiki";
|
|
|
|
locations = {
|
|
|
|
"~ ^/w/(index|load|api|thumb|opensearch_desc|rest|img_auth)\\.php$".extraConfig = ''
|
|
|
|
rewrite ^/w/(.*) /$1 break;
|
2023-11-25 00:47:31 +00:00
|
|
|
include ${config.services.nginx.package}/conf/fastcgi.conf;
|
2023-09-17 22:32:51 +00:00
|
|
|
fastcgi_index index.php;
|
|
|
|
fastcgi_pass unix:${config.services.phpfpm.pools.mediawiki.socket};
|
|
|
|
'';
|
|
|
|
"/w/images/".alias = withTrailingSlash cfg.uploadsDir;
|
|
|
|
# Deny access to deleted images folder
|
|
|
|
"/w/images/deleted".extraConfig = ''
|
|
|
|
deny all;
|
|
|
|
'';
|
|
|
|
# MediaWiki assets (usually images)
|
2023-11-04 13:10:45 +00:00
|
|
|
"~ ^/w/resources/(assets|lib|src)".extraConfig = ''
|
|
|
|
rewrite ^/w(/.*) $1 break;
|
|
|
|
add_header Cache-Control "public";
|
|
|
|
expires 7d;
|
|
|
|
'';
|
2023-09-17 22:32:51 +00:00
|
|
|
# Assets, scripts and styles from skins and extensions
|
2023-11-04 13:10:45 +00:00
|
|
|
"~ ^/w/(skins|extensions)/.+\\.(css|js|gif|jpg|jpeg|png|svg|wasm|ttf|woff|woff2)$".extraConfig = ''
|
|
|
|
rewrite ^/w(/.*) $1 break;
|
|
|
|
add_header Cache-Control "public";
|
|
|
|
expires 7d;
|
|
|
|
'';
|
2023-09-17 22:32:51 +00:00
|
|
|
|
|
|
|
# Handling for Mediawiki REST API, see [[mw:API:REST_API]]
|
2023-11-04 13:10:45 +00:00
|
|
|
"/w/rest.php/".tryFiles = "$uri $uri/ /w/rest.php?$query_string";
|
2023-09-17 22:32:51 +00:00
|
|
|
|
|
|
|
# Handling for the article path (pretty URLs)
|
|
|
|
"/wiki/".extraConfig = ''
|
|
|
|
rewrite ^/wiki/(?<pagename>.*)$ /w/index.php;
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Explicit access to the root website, redirect to main page (adapt as needed)
|
|
|
|
"= /".extraConfig = ''
|
2023-11-25 00:47:42 +00:00
|
|
|
return 301 /wiki/;
|
2023-09-17 22:32:51 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# Every other entry point will be disallowed.
|
|
|
|
# Add specific rules for other entry points/images as needed above this
|
|
|
|
"/".extraConfig = ''
|
|
|
|
return 404;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2019-06-06 01:19:11 +00:00
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${stateDir}' 0750 ${user} ${group} - -"
|
|
|
|
"d '${cacheDir}' 0750 ${user} ${group} - -"
|
|
|
|
] ++ optionals (cfg.uploadsDir != null) [
|
|
|
|
"d '${cfg.uploadsDir}' 0750 ${user} ${group} - -"
|
|
|
|
"Z '${cfg.uploadsDir}' 0750 ${user} ${group} - -"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.mediawiki-init = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
before = [ "phpfpm-mediawiki.service" ];
|
2023-04-03 15:05:21 +00:00
|
|
|
after = optional (cfg.database.type == "mysql" && cfg.database.createLocally) "mysql.service"
|
|
|
|
++ optional (cfg.database.type == "postgres" && cfg.database.createLocally) "postgresql.service";
|
2019-06-06 01:19:11 +00:00
|
|
|
script = ''
|
|
|
|
if ! test -e "${stateDir}/secret.key"; then
|
|
|
|
tr -dc A-Za-z0-9 </dev/urandom 2>/dev/null | head -c 64 > ${stateDir}/secret.key
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "exit( wfGetDB( DB_MASTER )->tableExists( 'user' ) ? 1 : 0 );" | \
|
2024-04-15 20:59:37 +00:00
|
|
|
${php}/bin/php ${pkg}/share/mediawiki/maintenance/eval.php --conf ${mediawikiConfig} && \
|
|
|
|
${php}/bin/php ${pkg}/share/mediawiki/maintenance/install.php \
|
2019-06-06 01:19:11 +00:00
|
|
|
--confpath /tmp \
|
|
|
|
--scriptpath / \
|
2023-11-11 14:36:36 +00:00
|
|
|
--dbserver ${lib.escapeShellArg dbAddr} \
|
2019-06-06 01:19:11 +00:00
|
|
|
--dbport ${toString cfg.database.port} \
|
2023-11-11 14:36:36 +00:00
|
|
|
--dbname ${lib.escapeShellArg cfg.database.name} \
|
|
|
|
${optionalString (cfg.database.tablePrefix != null) "--dbprefix ${lib.escapeShellArg cfg.database.tablePrefix}"} \
|
|
|
|
--dbuser ${lib.escapeShellArg cfg.database.user} \
|
|
|
|
${optionalString (cfg.database.passwordFile != null) "--dbpassfile ${lib.escapeShellArg cfg.database.passwordFile}"} \
|
|
|
|
--passfile ${lib.escapeShellArg cfg.passwordFile} \
|
2022-09-06 20:17:07 +00:00
|
|
|
--dbtype ${cfg.database.type} \
|
2023-11-11 14:36:36 +00:00
|
|
|
${lib.escapeShellArg cfg.name} \
|
2019-06-06 01:19:11 +00:00
|
|
|
admin
|
|
|
|
|
2024-04-15 20:59:37 +00:00
|
|
|
${php}/bin/php ${pkg}/share/mediawiki/maintenance/update.php --conf ${mediawikiConfig} --quick
|
2019-06-06 01:19:11 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = user;
|
|
|
|
Group = group;
|
|
|
|
PrivateTmp = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-04-24 12:21:06 +00:00
|
|
|
systemd.services.httpd.after = optional (cfg.webserver == "apache" && cfg.database.createLocally && cfg.database.type == "mysql") "mysql.service"
|
|
|
|
++ optional (cfg.webserver == "apache" && cfg.database.createLocally && cfg.database.type == "postgres") "postgresql.service";
|
2019-06-06 01:19:11 +00:00
|
|
|
|
2019-10-12 20:25:28 +00:00
|
|
|
users.users.${user} = {
|
2023-07-10 22:53:25 +00:00
|
|
|
inherit group;
|
2019-10-12 20:25:28 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
};
|
2023-04-24 12:21:06 +00:00
|
|
|
users.groups.${group} = {};
|
2019-06-06 01:19:11 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ mediawikiScripts ];
|
|
|
|
};
|
|
|
|
}
|