meta/target_software/Installing-MediaWiki-in-NixOS.md

61 lines
4.6 KiB
Markdown
Raw Permalink Normal View History

2024-10-21 09:22:04 +02:00
# Installing MediaWiki in NixOS
Installing MediaWiki in Nix can be easy, or daunting, depending on which web server you choose, and whether you like the configuration that the module leaves you with.
## Documentation
The [MediaWiki module](https://github.com/NixOS/nixpkgs/blob/nixos-24.05/pkgs/servers/web-apps/mediawiki/default.nix) is documented at <https://wiki.nixos.org/wiki/MediaWiki> and at <https://nixos.wiki/wiki/MediaWiki>. The former is a fork of the latter, but both branches have edits that are newer than that. They are still mostly the same, and it is unclear which of these wikis is a better choice for further contributions.
We preferred nginx over Apache, and as such were please to see that this module can be used with either. But it took us a few hours to realize why we couldn't get things working the way we wanted: the settings for `services.mediawiki.http` are ignored if you set `services.mediawiki.webserver` to `nginx` Apparently, `httpd` stands for the name of the Apache HTTPD, not just any HTTP daemon. The page offers no guidance on how to configure nginx with MediaWiki.
It took reading the source at `mediawiki.nix` to realize that nginx can be configured externally, and that the settings for MediaWiki will be merge with your own configuration if you the string for `services.mediawiki.nginx.hostName` as the key for `services.nginx.virtualHosts`.
## Functionality
Weirdly, the functionality provided by the module differs *wildly* based on the webserver choice. Not just the mechanism for configuring the virtual host is completely different, you get a different set of features configured: with nginx, you get nice URIs (`/wiki/PageName` instead of `/pathto/index.php?title=PageName`) and MediaWiki's presence is exposed through the `/w` path, but with Apache, you don't get that. That also means that although it seems simple enough to switch between webservers at a later point in time, this would break existing links.
It's notable that the prefix `/wiki` is not configurable. Since we're configuring for `wiki.fediversity.org` which already has `wiki` in the name, it would feel redundant and unnecessarily long to have `wiki` in the URLs a second time. It would be nice if the prefix was configurable, and specifically, if it could be left empty to get URLs like `https://example.org/PageName` instead of `https://example.org/wiki/PageName`. This should be doable with nginx with a "named location" (e.g. `location @mediawiki { ... }`) which sets `fastcgi_param SCRIPT_FILENAME` to the full path of `index.php`, and having `try_files $uri $uri/ @mediawiki` in the block for `location /`, but it was not clear how to integrate that by using `mediawiki.nix` and it feels like this would probably require changes to support this.
The module allows for installing MediaWiki extensions by providing the URL and hash for each extension, but the [installation instructions](https://www.semantic-mediawiki.org/wiki/Help:Installation/Quick_guide) for the venerable *Semantic MediaWiki* are more involved that just extracting a tarball. Since the functionality provided by Semantic MediaWiki is often one of the reasons to select MediaWiki over other other wiki software, it would be nice if NixOS newbie servers administrators could install it in NixOS.
## MediaWiki with nginx
```nix
services.mediawiki = {
enable = true;
name = "Fediversity Wiki";
webserver = "nginx";
nginx.hostName = "wiki.fediversity.eu";
passwordFile = pkgs.writeText "password" "<REDACTED>";
extraConfig = ...
};
services.nginx = {
enable = true;
virtualHosts."wiki.fediversity.eu" = {
forceSSL = true;
enableACME = true;
};
};
```
## Suggested improvements
- Make clear which wiki is preferred by the NixOS project for future contributions.
- (Preferrably, resolve whatever social sitution is causing the coexistence of the two wikis).
- Document that `services.mediawiki.httpd` is specific to Apache, or change the module to support these settings for nginx as well.
- Provide a full example for configuring MediaWiki on a virtual host with nginx, like the existing example for Apache, if this remains different depending on the chosen webserver.
- Provide the same functionality (i.e. URL rewriting) for the Apache HTTPD too.
- Alternatively, drop support for Apache HTTPD and support only nginx.
- Add a way to configure the URI prefix for pages (currently hard coded as `/wiki/`), including an option to use just `/`, or provide an example how to do this, if it is already possible.
- Provide a package or module, or extend the mediawiki module, for installing Semantic MediaWiki.