summary refs log tree commit diff
path: root/pkgs/servers/web-apps
diff options
context:
space:
mode:
authorFinn Behrens <me@kloenk.de>2020-06-18 12:34:31 +0200
committerFinn Behrens <me@kloenk.de>2020-07-16 23:48:02 +0200
commit7561a3dc4aad5f5811f585f75bb565153cf2f2d9 (patch)
tree6685ebe62036bf946c8f8c73255cc4ff35eb3240 /pkgs/servers/web-apps
parent951e2175c3070e98b154b211de53ca4c570295b3 (diff)
downloadnixpkgs-7561a3dc4aad5f5811f585f75bb565153cf2f2d9.tar
nixpkgs-7561a3dc4aad5f5811f585f75bb565153cf2f2d9.tar.gz
nixpkgs-7561a3dc4aad5f5811f585f75bb565153cf2f2d9.tar.bz2
nixpkgs-7561a3dc4aad5f5811f585f75bb565153cf2f2d9.tar.lz
nixpkgs-7561a3dc4aad5f5811f585f75bb565153cf2f2d9.tar.xz
nixpkgs-7561a3dc4aad5f5811f585f75bb565153cf2f2d9.tar.zst
nixpkgs-7561a3dc4aad5f5811f585f75bb565153cf2f2d9.zip
nixos/moodle: add plugins
Diffstat (limited to 'pkgs/servers/web-apps')
-rw-r--r--pkgs/servers/web-apps/moodle/default.nix41
-rw-r--r--pkgs/servers/web-apps/moodle/moodle-utils.nix32
2 files changed, 64 insertions, 9 deletions
diff --git a/pkgs/servers/web-apps/moodle/default.nix b/pkgs/servers/web-apps/moodle/default.nix
index b765a95c3fd..c466e2a3bb3 100644
--- a/pkgs/servers/web-apps/moodle/default.nix
+++ b/pkgs/servers/web-apps/moodle/default.nix
@@ -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 = "dffe8c1ac68938f50a987b46b0bfc74f01235d0198ac96fb4fc4f1df5bd7f4ea";
   };
 
   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 ];
diff --git a/pkgs/servers/web-apps/moodle/moodle-utils.nix b/pkgs/servers/web-apps/moodle/moodle-utils.nix
new file mode 100644
index 00000000000..52fddecc66d
--- /dev/null
+++ b/pkgs/servers/web-apps/moodle/moodle-utils.nix
@@ -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;
+}