# MediaWiki server for Wikipedia research # Copyright (C) 2023 Nguyễn Gia Phong # # This file is part of loang configuration. # # Loang configuration is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Loang configuration is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with loang configuration. If not, see . { config, lib, pkgs, ... }: let hostname = "nhanh.${config.networking.domain}"; in { services = { mediawiki = { database.type = "postgres"; enable = true; extensions = { # null means enabled here. Cite = null; Interwiki = null; }; extraConfig = '' $wgEnableEmail = false; $wgGroupPermissions['*']['read'] = false; $wgGroupPermissions['*']['edit'] = false; $wgGroupPermissions['*']['createaccount'] = false; $wgLogos = [ 'svg' => "https://upload.wikimedia.org/wikipedia/commons/e/e1/Wiki_research_logo.svg", ]; $wgFileExtensions = array_merge($wgFileExtensions, [ 'pdf' ]); ''; name = "Research on Wikipedia governance"; nginx.hostName = hostname; passwordFile = "/dev/null"; # this is so dumb webserver = "nginx"; }; nginx.virtualHosts.${hostname} = { enableACME = true; forceSSL = true; }; phpfpm.pools.mediawiki.phpOptions = '' post_max_size = 100M upload_max_filesize = 100M ''; postgresqlBackup.databases = [ "mediawiki" ]; }; systemd = let service = user: script: { inherit script; serviceConfig = { Type = "oneshot"; User = user; }; }; timer = unit: { wantedBy = [ "timers.target" ]; timerConfig = { OnBootSec = "1d"; OnUnitActiveSec = "1d"; Unit = "${unit}.service"; }; }; in { services = { "wiki-db-backup" = service "postgres" '' today=$(${pkgs.coreutils}/bin/date --iso-8601) backup=/mnt/nas/backup/nhanh.loang.net/$today.sql.zstd ${pkgs.coreutils}/bin/install -g mediawiki -m 640\ /mnt/nas/backup/postgresql/mediawiki.sql.zstd $backup ''; "wiki-uploads-backup" = service "mediawiki" '' backup=/mnt/nas/backup/nhanh.loang.net ${pkgs.rsync}/bin/rsync -a --delete\ ${config.services.mediawiki.uploadsDir}/ $backup/latest/ ${pkgs.coreutils}/bin/chown -R mediawiki:mediawiki $backup/latest/ today=$(${pkgs.coreutils}/bin/date --iso-8601) ${pkgs.coreutils}/bin/cp -al $backup/{latest,$today} ''; }; timers = { "wiki-db-backup" = timer "wiki-db-backup"; "wiki-uploads-backup" = timer "wiki-uploads-backup"; }; }; users.groups.mediawiki.members = [ "mediawiki" "nginx" "postgres" "ooze" "cnx" ]; }