2023-05-18 17:14:24 +02:00
|
|
|
{ pkgs, lib, config, values, ... }: let
|
|
|
|
cfg = config.services.mediawiki;
|
|
|
|
|
|
|
|
# "mediawiki"
|
|
|
|
user = config.systemd.services.mediawiki-init.serviceConfig.User;
|
|
|
|
|
|
|
|
# "mediawiki"
|
|
|
|
group = config.users.users.${user}.group;
|
|
|
|
in {
|
2023-01-29 01:51:35 +01:00
|
|
|
sops.secrets = {
|
2023-05-18 17:14:24 +02:00
|
|
|
"mediawiki/password" = {
|
|
|
|
restartUnits = [ "mediawiki-init.service" "phpfpm-mediawiki.service" ];
|
|
|
|
owner = user;
|
|
|
|
group = group;
|
|
|
|
};
|
|
|
|
"keys/postgres/mediawiki" = {
|
|
|
|
restartUnits = [ "mediawiki-init.service" "phpfpm-mediawiki.service" ];
|
|
|
|
owner = user;
|
|
|
|
group = group;
|
|
|
|
};
|
2023-01-29 01:51:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
services.mediawiki = {
|
|
|
|
enable = true;
|
2023-05-18 17:14:24 +02:00
|
|
|
name = "Programvareverkstedet";
|
2023-01-29 01:51:35 +01:00
|
|
|
passwordFile = config.sops.secrets."mediawiki/password".path;
|
2023-05-18 17:14:24 +02:00
|
|
|
passwordSender = "drift@pvv.ntnu.no";
|
2023-01-29 01:51:35 +01:00
|
|
|
|
|
|
|
database = {
|
|
|
|
type = "postgres";
|
2023-06-04 01:59:35 +02:00
|
|
|
host = "postgres.pvv.ntnu.no";
|
2023-01-29 01:51:35 +01:00
|
|
|
port = config.services.postgresql.port;
|
2023-05-18 17:14:24 +02:00
|
|
|
passwordFile = config.sops.secrets."keys/postgres/mediawiki".path;
|
|
|
|
createLocally = false;
|
|
|
|
# TODO: create a normal database and copy over old data when the service is production ready
|
|
|
|
name = "mediawiki_test";
|
2023-01-29 01:51:35 +01:00
|
|
|
};
|
2023-05-18 17:14:24 +02:00
|
|
|
|
|
|
|
# Host through nginx
|
|
|
|
webserver = "none";
|
|
|
|
poolConfig = let
|
|
|
|
listenUser = config.services.nginx.user;
|
|
|
|
listenGroup = config.services.nginx.group;
|
|
|
|
in {
|
|
|
|
inherit user group;
|
|
|
|
"pm" = "dynamic";
|
|
|
|
"pm.max_children" = 32;
|
|
|
|
"pm.max_requests" = 500;
|
|
|
|
"pm.start_servers" = 2;
|
|
|
|
"pm.min_spare_servers" = 2;
|
|
|
|
"pm.max_spare_servers" = 4;
|
|
|
|
"listen.owner" = listenUser;
|
|
|
|
"listen.group" = listenGroup;
|
|
|
|
"php_admin_value[error_log]" = "stderr";
|
|
|
|
"php_admin_flag[log_errors]" = "on";
|
|
|
|
"env[PATH]" = lib.makeBinPath [ pkgs.php ];
|
|
|
|
"catch_workers_output" = true;
|
|
|
|
# to accept *.html file
|
|
|
|
"security.limit_extensions" = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
extensions = {
|
|
|
|
DeleteBatch = pkgs.fetchzip {
|
|
|
|
url = "https://extdist.wmflabs.org/dist/extensions/DeleteBatch-REL1_39-995ea6f.tar.gz";
|
|
|
|
sha256 = "sha256-0F4GLCy2f5WcWIY2YgF1tVxgYbglR0VOsj/pMrW93b8=";
|
|
|
|
};
|
|
|
|
UserMerge = pkgs.fetchzip {
|
|
|
|
url = "https://extdist.wmflabs.org/dist/extensions/UserMerge-REL1_39-b10d50e.tar.gz";
|
|
|
|
sha256 = "sha256-bXhj1+OlOUJDbvEuc8iwqb1LLEu6cN6+C/7cAvnWPOQ=";
|
|
|
|
};
|
|
|
|
PluggableAuth = pkgs.fetchzip {
|
|
|
|
url = "https://extdist.wmflabs.org/dist/extensions/PluggableAuth-REL1_39-1210fc3.tar.gz";
|
|
|
|
sha256 = "sha256-F6bTMCzkK3kZwZGIsNE87WlZWqXXmTMhEjApO99YKR0=";
|
|
|
|
};
|
|
|
|
SimpleSAMLphp = pkgs.fetchzip {
|
|
|
|
url = "https://extdist.wmflabs.org/dist/extensions/SimpleSAMLphp-REL1_39-dcf0acb.tar.gz";
|
|
|
|
sha256 = "sha256-tCvFmb2+q2rxms+lRo5pgoI3h6GjCwXAR8XisPg03TQ=";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = let
|
|
|
|
|
|
|
|
SimpleSAMLphpRepo = pkgs.stdenvNoCC.mkDerivation rec {
|
|
|
|
pname = "configuredSimpleSAML";
|
|
|
|
version = "2.0.4";
|
|
|
|
src = pkgs.fetchzip {
|
|
|
|
url = "https://github.com/simplesamlphp/simplesamlphp/releases/download/v${version}/simplesamlphp-${version}.tar.gz";
|
|
|
|
sha256 = "sha256-pfMV/VmqqxgtG7Nx4s8MW4tWSaxOkVPtCRJwxV6RDSE=";
|
|
|
|
};
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
cat > config/authsources.php << EOF
|
|
|
|
<?php
|
|
|
|
$config = array(
|
|
|
|
'default-sp' => array(
|
|
|
|
'saml:SP',
|
|
|
|
'idp' => 'https://idp.pvv.ntnu.no/',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
cp -r . $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
in ''
|
|
|
|
$wgServer = "https://bekkalokk.pvv.ntnu.no";
|
|
|
|
$wgLocaltimezone = "Europe/Oslo";
|
|
|
|
|
|
|
|
# Only allow login through SSO
|
|
|
|
$wgEnableEmail = false;
|
|
|
|
$wgEnableUserEmail = false;
|
|
|
|
$wgEmailAuthentication = false;
|
|
|
|
$wgGroupPermissions['*']['createaccount'] = false;
|
|
|
|
$wgGroupPermissions['*']['autocreateaccount'] = true;
|
|
|
|
$wgPluggableAuth_EnableAutoLogin = true;
|
|
|
|
|
|
|
|
# Disable anonymous editing
|
|
|
|
$wgGroupPermissions['*']['edit'] = false;
|
|
|
|
|
|
|
|
# Styling
|
|
|
|
$wgLogo = "/PNG/PVV-logo.png";
|
|
|
|
$wgDefaultSkin = "monobook";
|
|
|
|
|
|
|
|
# Misc
|
|
|
|
$wgEmergencyContact = "${cfg.passwordSender}";
|
|
|
|
$wgShowIPinHeader = false;
|
|
|
|
$wgUseTeX = false;
|
|
|
|
$wgLocalInterwiki = $wgSitename;
|
|
|
|
|
|
|
|
# SimpleSAML
|
|
|
|
$wgSimpleSAMLphp_InstallDir = "${SimpleSAMLphpRepo}";
|
|
|
|
$wgSimpleSAMLphp_AuthSourceId = "default-sp";
|
|
|
|
$wgSimpleSAMLphp_RealNameAttribute = "cn";
|
|
|
|
$wgSimpleSAMLphp_EmailAttribute = "mail";
|
|
|
|
$wgSimpleSAMLphp_UsernameAttribute = "uid";
|
|
|
|
|
|
|
|
# Fix https://github.com/NixOS/nixpkgs/issues/183097
|
|
|
|
$wgDBserver = "${toString cfg.database.host}";
|
|
|
|
'';
|
2023-01-29 01:51:35 +01:00
|
|
|
};
|
2023-05-18 17:14:24 +02:00
|
|
|
|
|
|
|
# Override because of https://github.com/NixOS/nixpkgs/issues/183097
|
|
|
|
systemd.services.mediawiki-init.script = let
|
|
|
|
# According to module
|
|
|
|
stateDir = "/var/lib/mediawiki";
|
|
|
|
pkg = cfg.finalPackage;
|
|
|
|
mediawikiConfig = config.services.phpfpm.pools.mediawiki.phpEnv.MEDIAWIKI_CONFIG;
|
|
|
|
inherit (lib) optionalString mkForce;
|
|
|
|
in mkForce ''
|
|
|
|
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 );" | \
|
|
|
|
${pkgs.php}/bin/php ${pkg}/share/mediawiki/maintenance/eval.php --conf ${mediawikiConfig} && \
|
|
|
|
${pkgs.php}/bin/php ${pkg}/share/mediawiki/maintenance/install.php \
|
|
|
|
--confpath /tmp \
|
|
|
|
--scriptpath / \
|
|
|
|
--dbserver "${cfg.database.host}" \
|
|
|
|
--dbport ${toString cfg.database.port} \
|
|
|
|
--dbname ${cfg.database.name} \
|
|
|
|
${optionalString (cfg.database.tablePrefix != null) "--dbprefix ${cfg.database.tablePrefix}"} \
|
|
|
|
--dbuser ${cfg.database.user} \
|
|
|
|
${optionalString (cfg.database.passwordFile != null) "--dbpassfile ${cfg.database.passwordFile}"} \
|
|
|
|
--passfile ${cfg.passwordFile} \
|
|
|
|
--dbtype ${cfg.database.type} \
|
|
|
|
${cfg.name} \
|
|
|
|
admin
|
|
|
|
|
|
|
|
${pkgs.php}/bin/php ${pkg}/share/mediawiki/maintenance/update.php --conf ${mediawikiConfig} --quick
|
|
|
|
'';
|
2023-01-29 01:51:35 +01:00
|
|
|
}
|