at master 146 lines 3.9 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 writeText, 6 plugins ? [ ], 7 nixosTests, 8}: 9 10let 11 version = "5.0.2"; 12 13 versionParts = lib.take 2 (lib.splitVersion version); 14 # 4.2 -> 402, 3.11 -> 311 15 stableVersion = lib.removePrefix "0" ( 16 lib.concatMapStrings ( 17 p: 18 if (lib.toInt p) < 10 then 19 (lib.concatStrings [ 20 "0" 21 p 22 ]) 23 else 24 p 25 ) versionParts 26 ); 27 28 # Reference: https://docs.moodle.org/dev/Plugin_types 29 pluginDirs = { 30 mod = "mod"; 31 antivirus = "lib/antivirus"; 32 assignsubmission = "mod/assign/submission"; 33 assignfeedback = "mod/assign/feedback"; 34 booktool = "mod/book/tool"; 35 customfield = "customfield/field"; 36 datafield = "mod/data/field"; 37 datapreset = "mod/data/preset"; 38 ltisource = "mod/lti/source"; 39 fileconverter = "files/converter"; 40 ltiservice = "mod/lti/service"; 41 mlbackend = "lib/mlbackend"; 42 forumreport = "mod/forum/report"; 43 quiz = "mod/quiz/report"; 44 quizaccess = "mod/quiz/accessrule"; 45 scormreport = "mod/scorm/report"; 46 workshopform = "mod/workshop/form"; 47 workshopallocation = "mod/workshop/allocation"; 48 workshopeval = "mod/workshop/eval"; 49 block = "blocks"; 50 qtype = "question/type"; 51 qbehaviour = "question/behaviour"; 52 qformat = "question/format"; 53 filter = "filter"; 54 editor = "lib/editor"; 55 atto = "lib/editor/atto/plugins"; 56 tinymce = "lib/editor/tinymce/plugins"; 57 enrol = "enrol"; 58 auth = "auth"; 59 tool = "admin/tool"; 60 logstore = "admin/tool/log/store"; 61 availability = "availability/condition"; 62 calendartype = "calendar/type"; 63 message = "message/output"; 64 format = "course/format"; 65 dataformat = "dataformat"; 66 profilefield = "user/profile/field"; 67 report = "report"; 68 # coursereport = "course/report"; # Moved to /report 69 gradeexport = "grade/export"; 70 gradeimport = "grade/import"; 71 gradereport = "grade/report"; 72 gradingform = "grade/grading/form"; 73 mnetservice = "mnet/service"; 74 webservice = "webservice"; 75 repository = "repository"; 76 portfolio = "portfolio"; 77 search = "search/engine"; 78 media = "media/player"; 79 plagiarism = "plagiarism"; 80 cachestore = "cache/stores"; 81 cachelock = "cache/locks"; 82 theme = "theme"; 83 local = "local"; 84 # assignment = "mod/assignment/type"; # Deprecated 85 # report = "admin/report"; # Moved to /report 86 contenttype = "contentbank/contenttype"; 87 h5plib = "h5p/h5plib"; 88 qbank = "question/bank"; 89 }; 90 91in 92stdenv.mkDerivation rec { 93 pname = "moodle"; 94 inherit version; 95 96 src = fetchurl { 97 url = "https://download.moodle.org/download.php/direct/stable${stableVersion}/${pname}-${version}.tgz"; 98 hash = "sha256-p9kXrUnsFNHJ3k5EwSYO/iXNlN1AanOGln1TQSFiCUI="; 99 }; 100 101 phpConfig = writeText "config.php" '' 102 <?php 103 return require(getenv('MOODLE_CONFIG')); 104 ?> 105 ''; 106 107 installPhase = '' 108 runHook preInstall 109 110 mkdir -p $out/share/moodle 111 cp -r . $out/share/moodle 112 cp ${phpConfig} $out/share/moodle/config.php 113 114 ${lib.concatStringsSep "\n" ( 115 map ( 116 p: 117 let 118 dir = 119 if (lib.hasAttr p.pluginType pluginDirs) then 120 pluginDirs.${p.pluginType} 121 else 122 throw "unknown moodle plugin type"; 123 # we have to copy it, because the plugins have refrences to .. inside 124 in 125 '' 126 mkdir -p $out/share/moodle/${dir}/${p.name} 127 cp -r ${p}/* $out/share/moodle/${dir}/${p.name}/ 128 '' 129 ) plugins 130 )} 131 132 runHook postInstall 133 ''; 134 135 passthru.tests = { 136 inherit (nixosTests) moodle; 137 }; 138 139 meta = with lib; { 140 description = "Free and open-source learning management system (LMS) written in PHP"; 141 license = licenses.gpl3Plus; 142 homepage = "https://moodle.org/"; 143 maintainers = with maintainers; [ freezeboy ]; 144 platforms = platforms.all; 145 }; 146}