2023-11-04 23:16:15 +01:00
|
|
|
{ pkgs, lib, config, values, pkgs-unstable, ... }: let
|
2023-05-18 17:14:24 +02:00
|
|
|
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;
|
|
|
|
};
|
2023-11-04 23:16:15 +01:00
|
|
|
"mediawiki/database" = {
|
2023-05-18 17:14:24 +02:00
|
|
|
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-11-04 23:16:15 +01:00
|
|
|
passwordFile = config.sops.secrets."mediawiki/database".path;
|
2023-05-18 17:14:24 +02:00
|
|
|
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 {
|
2023-11-04 23:16:15 +01:00
|
|
|
name = "mediawiki-delete-batch-source";
|
|
|
|
url = "https://extdist.wmflabs.org/dist/extensions/DeleteBatch-REL1_40-4fe36dc.tar.gz";
|
|
|
|
hash = "sha256-jmRkjHFQR9cjPr1eBHVDLHm0xO4OPn9HYiYwrkBT/aA=";
|
2023-05-18 17:14:24 +02:00
|
|
|
};
|
|
|
|
UserMerge = pkgs.fetchzip {
|
2023-11-04 23:16:15 +01:00
|
|
|
name = "mediawiki-user-merge-source";
|
|
|
|
url = "https://extdist.wmflabs.org/dist/extensions/UserMerge-REL1_40-7407806.tar.gz";
|
|
|
|
hash = "sha256-NHAw79pDxjia46J5DIGV9AoF9UazSahT8DZgUUn/pQE=";
|
2023-05-18 17:14:24 +02:00
|
|
|
};
|
|
|
|
PluggableAuth = pkgs.fetchzip {
|
2023-11-04 23:16:15 +01:00
|
|
|
name = "mediawiki-pluggable-auth-source";
|
|
|
|
url = "https://extdist.wmflabs.org/dist/extensions/PluggableAuth-REL1_40-eb10a76.tar.gz";
|
|
|
|
hash = "sha256-GFmtQc0SeBpvI+7iHOVw77JR2h+hwPxo8+wZ9RED8a8=";
|
2023-05-18 17:14:24 +02:00
|
|
|
};
|
|
|
|
SimpleSAMLphp = pkgs.fetchzip {
|
2023-11-04 23:16:15 +01:00
|
|
|
name = "mediawiki-simple-saml-php-source";
|
|
|
|
url = "https://extdist.wmflabs.org/dist/extensions/SimpleSAMLphp-REL1_40-8043943.tar.gz";
|
|
|
|
hash = "sha256-HJHcrv/FNqPJegrHo4VPVjw0alkyHwetFZiLwjHsf6Y=";
|
2023-05-18 17:14:24 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = let
|
2023-11-04 23:16:15 +01:00
|
|
|
SimpleSAMLphpRepo = pkgs-unstable.php.buildComposerProject rec {
|
2023-05-18 17:14:24 +02:00
|
|
|
pname = "configuredSimpleSAML";
|
2023-11-04 23:16:15 +01:00
|
|
|
version = "2.1.0-rc1";
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "simplesamlphp";
|
|
|
|
repo = "simplesamlphp";
|
|
|
|
# name = "simple-saml-php-source";
|
|
|
|
# url = "https://github.com/simplesamlphp/simplesamlphp/releases/download/v${version}/simplesamlphp-${version}.tar.gz";
|
|
|
|
rev = "v${version}";
|
|
|
|
hash = "sha256-E7S6T/EfuhNbe697OiklZ77wMRkOb/ABJXoL5MphMCY=";
|
2023-05-18 17:14:24 +02:00
|
|
|
};
|
|
|
|
|
2023-11-04 23:16:15 +01:00
|
|
|
composerStrictValidation = false;
|
|
|
|
|
|
|
|
vendorHash = "sha256-vr9mWXN9v6tGNvPtxQ+pgf7OYj8dedzWfxt6Xw1nCm0=";
|
|
|
|
|
|
|
|
configAuthsourcesPhp = ''
|
2023-05-18 17:14:24 +02:00
|
|
|
<?php
|
|
|
|
$config = array(
|
|
|
|
'default-sp' => array(
|
|
|
|
'saml:SP',
|
|
|
|
'idp' => 'https://idp.pvv.ntnu.no/',
|
|
|
|
),
|
|
|
|
);
|
2023-11-04 23:16:15 +01:00
|
|
|
'';
|
2023-05-18 17:14:24 +02:00
|
|
|
|
2023-11-04 23:16:15 +01:00
|
|
|
# TODO: this could be fetched automagically with these:
|
|
|
|
# - https://simplesamlphp.org/docs/contrib_modules/metarefresh/simplesamlphp-automated_metadata.html
|
|
|
|
# - https://idp.pvv.ntnu.no/simplesaml/saml2/idp/metadata.php
|
|
|
|
metadataSaml20IdpRemotePhp = ''
|
|
|
|
<?php
|
|
|
|
$metadata['https://idp.pvv.ntnu.no/'] = array (
|
|
|
|
'metadata-set' => 'saml20-idp-remote',
|
|
|
|
'entityid' => 'https://idp.pvv.ntnu.no/',
|
|
|
|
'SingleSignOnService' =>
|
|
|
|
array (
|
|
|
|
0 =>
|
|
|
|
array (
|
|
|
|
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
|
|
|
|
'Location' => 'https://idp.pvv.ntnu.no/simplesaml/saml2/idp/SSOService.php',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'SingleLogoutService' =>
|
|
|
|
array (
|
|
|
|
0 =>
|
|
|
|
array (
|
|
|
|
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
|
|
|
|
'Location' => 'https://idp.pvv.ntnu.no/simplesaml/saml2/idp/SingleLogoutService.php',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'certData' => 'pvvcert.pem',
|
|
|
|
'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient',
|
|
|
|
);
|
|
|
|
'';
|
|
|
|
|
|
|
|
pvvcert = ''
|
|
|
|
MIIDpTCCAo2gAwIBAgIJAJIgibrB7NvsMA0GCSqGSIb3DQEBCwUAMGkxCzAJBgNVBAYTAk5PMR4wHAYDVQQKDBVQcm9ncmFtdmFyZXZlcmtzdGVkZXQxGDAWBgNVBAMMD2lkcC5wdnYub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dKdzpmfk7zPVxWlNxNCZ7OPNuvOKp6VlpB2EA==
|
|
|
|
'';
|
|
|
|
|
|
|
|
passAsFile = [
|
|
|
|
"configAuthsourcesPhp"
|
|
|
|
"metadataSaml20IdpRemotePhp"
|
|
|
|
"pvvcert"
|
|
|
|
];
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
install -Dm444 "$configAuthsourcesPhpPath" "config/authsources.php"
|
|
|
|
install -Dm444 "$metadataSaml20IdpRemotePhpPath" "metadata/saml20-idp-remote.php"
|
|
|
|
install -Dm444 "$pvvcertPath" "cert/pvvcert.pem"
|
2023-05-18 17:14:24 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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-11-04 23:16:15 +01:00
|
|
|
|
|
|
|
services.nginx.virtualHosts."bekkalokk.pvv.ntnu.no" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
root = "${config.services.mediawiki.finalPackage}/share/mediawiki";
|
|
|
|
locations = {
|
|
|
|
"/" = {
|
|
|
|
extraConfig = ''
|
|
|
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
|
|
|
fastcgi_index index.php;
|
|
|
|
fastcgi_pass unix:${config.services.phpfpm.pools.mediawiki.socket};
|
|
|
|
include ${pkgs.nginx}/conf/fastcgi_params;
|
|
|
|
include ${pkgs.nginx}/conf/fastcgi.conf;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
"/images".root = config.services.mediawiki.uploadsDir;
|
|
|
|
};
|
|
|
|
};
|
2023-01-29 01:51:35 +01:00
|
|
|
}
|