aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/servers/web-apps/moodle/default.nix
blob: b9f11b5c1798ab93ab3eeb36f2f1ac962db892e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{ lib, stdenv, fetchurl, writeText, plugins ? [ ] }:

let
  version = "3.9.2";
  stableVersion = builtins.substring 0 2 (builtins.replaceStrings ["."] [""] version);

in stdenv.mkDerivation rec {
  pname = "moodle";
  inherit version;

  src = fetchurl {
    url =
      "https://download.moodle.org/stable${stableVersion}/${pname}-${version}.tgz";
    sha256 = "ygy9xlYs49Ga3u2Q/vqxhnDnqXsrh6YYTAtcsXF8kNo=";
  };

  phpConfig = writeText "config.php" ''
    <?php
      return require(getenv('MOODLE_CONFIG'));
    ?>
  '';

  installPhase = ''
    runHook preInstall

    mkdir -p $out/share/moodle
    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";
    license = licenses.gpl3Plus;
    homepage = "https://moodle.org/";
    maintainers = with maintainers; [ freezeboy ];
    platforms = platforms.all;
  };
}