nixos-wiki-infra/modules/nixos-wiki/default.nix
2023-11-19 11:38:31 +01:00

139 lines
4.5 KiB
Nix

{ config, pkgs, lib, ... }:
let
cfg = config.services.nixos-wiki;
in
{
options = {
services.nixos-wiki = {
hostname = lib.mkOption {
type = lib.types.str;
description = "The hostname of the wiki";
};
adminPasswordFile = lib.mkOption {
type = lib.types.path;
description = "The password file for the wiki admin";
};
githubClientId = lib.mkOption {
type = lib.types.str;
description = "The github client id for the wiki";
};
githubClientSecretFile = lib.mkOption {
type = lib.types.path;
description = "The github client secret for the wiki";
};
emergencyContact = lib.mkOption {
type = lib.types.str;
description = "The emergency contact for the wiki";
};
passwordSender = lib.mkOption {
type = lib.types.str;
description = "default FROM address in emails";
};
noReplyAddress = lib.mkOption {
type = lib.types.str;
description = "default Reply-To address in emails";
};
};
};
config = {
services.mediawiki = {
enable = true;
webserver = "nginx";
database.type = "postgres";
nginx.hostName = config.services.nixos-wiki.hostname;
uploadsDir = "/var/lib/mediawiki-uploads/";
passwordFile = cfg.adminPasswordFile;
extensions.SyntaxHighlight_GeSHi = null; # provides <SyntaxHighlight> tags
extensions.ParserFunctions = null;
extensions.Cite = null;
extensions.VisualEditor = null;
extensions.AuthManagerOAuth = pkgs.fetchzip {
url = "https://github.com/mohe2015/AuthManagerOAuth/releases/download/v0.3.2/AuthManagerOAuth.zip";
hash = "sha256-hr/DLyL6IzQs67eA46RdmuVlfCiAbq+eZCRLfjLxUpc=";
}; # Github login
extensions.ConfirmEdit = null; # Combat SPAM with a simple Captcha
extensions.StopForumSpam = pkgs.fetchzip {
url = "https://extdist.wmflabs.org/dist/extensions/StopForumSpam-REL1_40-71b57ba.tar.gz";
hash = "sha256-g8v4zr11c2e4bY0BNipJ48miyAF4WTNvlSMgb/NxPBA=";
};
extraConfig = ''
#$wgDebugLogFile = "/var/log/mediawiki/debug.log";
# allow local login
$wgAuthManagerOAuthConfig = [
'github' => [
'clientId' => '${cfg.githubClientId}',
'clientSecret' => file_get_contents("${cfg.githubClientSecretFile}"),
'urlAuthorize' => 'https://github.com/login/oauth/authorize',
'urlAccessToken' => 'https://github.com/login/oauth/access_token',
'urlResourceOwnerDetails' => 'https://api.github.com/user'
],
];
# Enable account creation globally
$wgGroupPermissions['*']['createaccount'] = true;
$wgGroupPermissions['*']['autocreateaccount'] = true;
# Disable anonymous editing
$wgGroupPermissions['*']['edit'] = false;
# Allow svg upload
$wgFileExtensions[] = 'svg';
$wgSVGConverterPath = "${pkgs.imagemagick}/bin";
# Pretty URLs
$wgUsePathInfo = true;
# cache pages with APCu
$wgMainCacheType = CACHE_ACCEL;
# TODO: nixos favicon
#$wgFavicon = "/favicon.ico";
$wgDefaultSkin = 'vector-2022';
# configure logos for vector-2022: https://www.mediawiki.org/wiki/Manual:$wgLogos
$wgLogos = [
'1x' => '/nixos.png',
'icon' => '/nixos.png',
];
# Combat SPAM with IP-Blocklists (StopForumSpam extension)
$wgEnableDnsBlacklist = true;
$wgDnsBlacklistUrls = array(
'dnsbl.dronebl.org'
);
# required for fancy VisualEditor extension
$wgGroupPermissions['user']['writeapi'] = true;
# Enable content security policy
$wgCSPHeader = true;
# Disallow framing
$wgEditPageFrameOptions = "DENY";
$wgEnableEmail = true;
$wgAllowHTMLEmail = false;
$wgEmergencyContact = "${cfg.emergencyContact}";
$wgPasswordSender = "${cfg.passwordSender}";
$wgNoReplyAddress = "${cfg.noReplyAddress}";
# To purge all page cache increase this using: date +%Y%m%d%H%M%S
$wgCacheEpoch = 20231115172319;
'';
};
networking.firewall.allowedTCPPorts = [ 443 80 ];
security.acme.acceptTerms = true;
services.nginx.virtualHosts.${config.services.mediawiki.nginx.hostName} = {
enableACME = lib.mkDefault true;
forceSSL = lib.mkDefault true;
locations."=/nixos.png".alias = ./nixos.png;
};
};
}