Merge pull request #93104 from Kloenk/moodle-plugins

nixos/moodle: add plugins
This commit is contained in:
Lassulus 2020-07-17 17:47:11 +02:00 committed by GitHub
commit b6eca9a2af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 14 deletions

View file

@ -40,7 +40,7 @@ let
$CFG->disableupdateautodeploy = true;
$CFG->pathtogs = '${pkgs.ghostscript}/bin/gs';
$CFG->pathtophp = '${pkgs.php}/bin/php';
$CFG->pathtophp = '${phpExt}/bin/php';
$CFG->pathtodu = '${pkgs.coreutils}/bin/du';
$CFG->aspellpath = '${pkgs.aspell}/bin/aspell';
$CFG->pathtodot = '${pkgs.graphviz}/bin/dot';
@ -55,6 +55,9 @@ let
mysqlLocal = cfg.database.createLocally && cfg.database.type == "mysql";
pgsqlLocal = cfg.database.createLocally && cfg.database.type == "pgsql";
phpExt = pkgs.php.withExtensions
({ enabled, all }: with all; [ iconv mbstring curl openssl tokenizer xmlrpc soap ctype zip gd simplexml dom intl json sqlite3 pgsql pdo_sqlite pdo_pgsql pdo_odbc pdo_mysql pdo mysqli session zlib xmlreader fileinfo ]);
in
{
# interface
@ -222,6 +225,7 @@ in
services.phpfpm.pools.moodle = {
inherit user group;
phpPackage = phpExt;
phpEnv.MOODLE_CONFIG = "${moodleConfig}";
phpOptions = ''
zend_extension = opcache.so
@ -263,13 +267,13 @@ in
after = optional mysqlLocal "mysql.service" ++ optional pgsqlLocal "postgresql.service";
environment.MOODLE_CONFIG = moodleConfig;
script = ''
${pkgs.php}/bin/php ${cfg.package}/share/moodle/admin/cli/check_database_schema.php && rc=$? || rc=$?
${phpExt}/bin/php ${cfg.package}/share/moodle/admin/cli/check_database_schema.php && rc=$? || rc=$?
[ "$rc" == 1 ] && ${pkgs.php}/bin/php ${cfg.package}/share/moodle/admin/cli/upgrade.php \
[ "$rc" == 1 ] && ${phpExt}/bin/php ${cfg.package}/share/moodle/admin/cli/upgrade.php \
--non-interactive \
--allow-unstable
[ "$rc" == 2 ] && ${pkgs.php}/bin/php ${cfg.package}/share/moodle/admin/cli/install_database.php \
[ "$rc" == 2 ] && ${phpExt}/bin/php ${cfg.package}/share/moodle/admin/cli/install_database.php \
--agree-license \
--adminpass=${cfg.initialPassword}
@ -289,7 +293,7 @@ in
serviceConfig = {
User = user;
Group = group;
ExecStart = "${pkgs.php}/bin/php ${cfg.package}/share/moodle/admin/cli/cron.php";
ExecStart = "${phpExt}/bin/php ${cfg.package}/share/moodle/admin/cli/cron.php";
};
};

View file

@ -1,23 +1,23 @@
{ stdenv, fetchurl, writeText }:
{ lib, stdenv, fetchurl, writeText, plugins ? [ ] }:
let
version = "3.9.1";
stableVersion = builtins.substring 0 2 (builtins.replaceStrings ["."] [""] version);
in
stdenv.mkDerivation rec {
in stdenv.mkDerivation rec {
pname = "moodle";
inherit version;
src = fetchurl {
url = "https://download.moodle.org/stable${stableVersion}/${pname}-${version}.tgz";
sha256 = "1ysnrk013gmc21ml3jwijvl16rx3p478a4vriy6h8hfli48460p9";
url =
"https://download.moodle.org/stable${stableVersion}/${pname}-${version}.tgz";
sha256 = "sha256-6QJDEInUQQSNj3kThQ65o2cT6JaRy0FrEKy+EcDMVvs=";
};
phpConfig = writeText "config.php" ''
<?php
return require(getenv('MOODLE_CONFIG'));
?>
<?php
return require(getenv('MOODLE_CONFIG'));
?>
'';
installPhase = ''
@ -27,11 +27,34 @@ stdenv.mkDerivation rec {
cp -r . $out/share/moodle
cp ${phpConfig} $out/share/moodle/config.php
${lib.concatStringsSep "\n" (map (p:
let
dir = if p.pluginType == "mod" then
"mod"
else if p.pluginType == "theme" then
"theme"
else if p.pluginType == "block" then
"blocks"
else if p.pluginType == "question" then
"question/type"
else if p.pluginType == "course" then
"course/format"
else if p.pluginType == "report" then
"admin/report"
else
throw "unknown moodle plugin type";
# we have to copy it, because the plugins have refrences to .. inside
in ''
mkdir -p $out/share/moodle/${dir}/${p.name}
cp -r ${p}/* $out/share/moodle/${dir}/${p.name}/
'') plugins)}
runHook postInstall
'';
meta = with stdenv.lib; {
description = "Free and open-source learning management system (LMS) written in PHP";
description =
"Free and open-source learning management system (LMS) written in PHP";
license = licenses.gpl3Plus;
homepage = "https://moodle.org/";
maintainers = with maintainers; [ aanderse ];

View file

@ -0,0 +1,32 @@
{ stdenv, unzip, ... }:
let
buildMoodlePlugin = a@{
name,
src,
pluginType,
configuraPhase ? ":",
buildPhase ? ":",
buildInputs ? [ ],
...
}:
stdenv.mkDerivation (a // {
name = name;
inherit pluginType;
inherit configuraPhase buildPhase;
buildInputs = [ unzip ] ++ buildInputs;
installPhase = ''
runHook preInstall
mkdir -p "$out"
mv * $out/
runHook postInstall
'';
});
in {
inherit buildMoodlePlugin;
}

View file

@ -16060,6 +16060,8 @@ in
moodle = callPackage ../servers/web-apps/moodle { };
moodle-utils = callPackage ../servers/web-apps/moodle/moodle-utils.nix { };
morty = callPackage ../servers/web-apps/morty { };
mullvad-vpn = callPackage ../applications/networking/mullvad-vpn { };