diff --git a/nixos/modules/services/web-apps/mediawiki.nix b/nixos/modules/services/web-apps/mediawiki.nix index 565f4a37c744..af1dbcd223a7 100644 --- a/nixos/modules/services/web-apps/mediawiki.nix +++ b/nixos/modules/services/web-apps/mediawiki.nix @@ -123,129 +123,141 @@ let checkPhase = '' ${cfg.phpPackage}/bin/php --syntax-check "$target" ''; - text = '' - . ''; }; @@ -462,7 +490,7 @@ in else null; defaultText = literalExpression "/run/mysqld/mysqld.sock"; - description = "Path to the unix socket file to use for authentication."; + description = "Path to the unix socket file to use for authentication. Used only if database type is not SQLite."; }; createLocally = mkOption { @@ -570,6 +598,28 @@ in } ]; + warnings = + lib.optional + ( + cfg.database.type == "sqlite" + && ( + cfg.database.host != null + || cfg.database.port != null + || cfg.database.user != null + || cfg.database.passwordFile != null + || cfg.database.socket != null + ) + ) + '' + The services.mediawiki.database options host, port, user, passwordFile, and socket will be ignored because services.mediawiki.database.type is "sqlite". + '' + ++ lib.optional (cfg.database.type != "sqlite" && cfg.database.path != null) '' + The services.mediawiki.database.path option will be ignored because services.mediawiki.database.type is not "sqlite". + '' + ++ lib.optional (cfg.database.type == "mysql" && cfg.database.tablePrefix != null) '' + The services.mediawiki.database.tablePrefix option has no effect when the services.mediawiki.database.type is not "mysql". + ''; + services.mediawiki = { path = with pkgs; [ diffutils @@ -728,37 +778,52 @@ in after = optional (cfg.database.type == "mysql" && cfg.database.createLocally) "mysql.service" ++ optional (cfg.database.type == "postgres" && cfg.database.createLocally) "postgresql.target"; - script = '' - if ! test -e "${stateDir}/secret.key"; then - tr -dc A-Za-z0-9 /dev/null | head -c 64 > ${stateDir}/secret.key - fi + script = + let + dbOptions = + if cfg.database.type == "sqlite" then + '' + --dbpath ${lib.escapeShellArg cfg.database.path} \ + --dbname ${lib.escapeShellArg cfg.database.name} \ + '' + else + '' + --dbserver ${lib.escapeShellArg dbAddr} \ + --dbport ${toString cfg.database.port} \ + --dbname ${lib.escapeShellArg cfg.database.name} \ + ${ + optionalString ( + cfg.database.tablePrefix != null + ) "--dbprefix ${lib.escapeShellArg cfg.database.tablePrefix}" + } \ + --dbuser ${lib.escapeShellArg cfg.database.user} \ + ${ + optionalString ( + cfg.database.passwordFile != null + ) "--dbpassfile ${lib.escapeShellArg cfg.database.passwordFile}" + } \ + ''; + in + '' + if ! test -e "${stateDir}/secret.key"; then + tr -dc A-Za-z0-9 /dev/null | head -c 64 > ${stateDir}/secret.key + fi - echo "exit( \$this->getPrimaryDB()->tableExists( 'user' ) ? 1 : 0 );" | \ - ${cfg.phpPackage}/bin/php ${pkg}/share/mediawiki/maintenance/run.php eval --conf ${mediawikiConfig} && \ - ${cfg.phpPackage}/bin/php ${pkg}/share/mediawiki/maintenance/run.php ${pkg}/share/mediawiki/maintenance/install.php \ - --confpath /tmp \ - --scriptpath / \ - --dbserver ${lib.escapeShellArg dbAddr} \ - --dbport ${toString cfg.database.port} \ - --dbname ${lib.escapeShellArg cfg.database.name} \ - ${ - optionalString ( - cfg.database.tablePrefix != null - ) "--dbprefix ${lib.escapeShellArg cfg.database.tablePrefix}" - } \ - --dbuser ${lib.escapeShellArg cfg.database.user} \ - ${ - optionalString ( - cfg.database.passwordFile != null - ) "--dbpassfile ${lib.escapeShellArg cfg.database.passwordFile}" - } \ - --passfile ${lib.escapeShellArg cfg.passwordFile} \ - --dbtype ${cfg.database.type} \ - ${lib.escapeShellArg cfg.name} \ - admin + ${optionalString (cfg.database.type == "sqlite") "mkdir -p ${cfg.database.path}"} - ${cfg.phpPackage}/bin/php ${pkg}/share/mediawiki/maintenance/update.php --conf ${mediawikiConfig} --quick --skip-external-dependencies - ''; + echo "exit( \$this->getPrimaryDB()->tableExists( 'user' ) ? 1 : 0 );" | \ + ${cfg.phpPackage}/bin/php ${pkg}/share/mediawiki/maintenance/run.php eval --conf ${mediawikiConfig} && \ + ${cfg.phpPackage}/bin/php ${pkg}/share/mediawiki/maintenance/run.php ${pkg}/share/mediawiki/maintenance/install.php \ + --confpath /tmp \ + --scriptpath / \ + ${dbOptions} \ + --dbtype ${cfg.database.type} \ + --passfile ${lib.escapeShellArg cfg.passwordFile} \ + ${lib.escapeShellArg cfg.name} \ + admin + + ${cfg.phpPackage}/bin/php ${pkg}/share/mediawiki/maintenance/update.php --conf ${mediawikiConfig} --quick --skip-external-dependencies + ''; serviceConfig = { Type = "oneshot"; diff --git a/nixos/tests/mediawiki.nix b/nixos/tests/mediawiki.nix index deb714e6b178..fedae1675d7c 100644 --- a/nixos/tests/mediawiki.nix +++ b/nixos/tests/mediawiki.nix @@ -57,6 +57,21 @@ in ''; }; + sqlite = makeTest { + name = "mediawiki-sqlite"; + nodes.machine = { + services.mediawiki.database.type = "sqlite"; + }; + testScript = '' + start_all() + + machine.wait_for_unit("phpfpm-mediawiki.service") + + page = machine.succeed("curl -fL http://localhost/") + assert "MediaWiki has been installed" in page + ''; + }; + nohttpd = makeTest { name = "mediawiki-nohttpd"; nodes.machine = {