1{ config, lib, pkgs, serverInfo, php, ... }:
2
3with lib;
4
5let
6
7 httpd = serverInfo.serverConfig.package;
8
9 version24 = !versionOlder httpd.version "2.4";
10
11 allGranted = if version24 then ''
12 Require all granted
13 '' else ''
14 Order allow,deny
15 Allow from all
16 '';
17
18 moodleConfig = pkgs.writeText "config.php"
19 ''
20 <?php
21 unset($CFG);
22 global $CFG;
23 $CFG = new stdClass();
24 $CFG->dbtype = '${config.dbType}';
25 $CFG->dblibrary = 'native';
26 $CFG->dbhost = '${config.dbHost}';
27 $CFG->dbname = '${config.dbName}';
28 $CFG->dbuser = '${config.dbUser}';
29 $CFG->dbpass = '${config.dbPassword}';
30 $CFG->prefix = '${config.dbPrefix}';
31 $CFG->dboptions = array(
32 'dbpersist' => false,
33 'dbsocket' => false,
34 'dbport' => "${config.dbPort}",
35 );
36 $CFG->wwwroot = '${config.wwwRoot}';
37 $CFG->dataroot = '${config.dataRoot}';
38 $CFG->directorypermissions = 02777;
39 $CFG->admin = 'admin';
40 ${optionalString (config.debug.noEmailEver == true) ''
41 $CFG->noemailever = true;
42 ''}
43
44 ${config.extraConfig}
45 require_once(dirname(__FILE__) . '/lib/setup.php'); // Do not edit
46 '';
47 # Unpack Moodle and put the config file in its root directory.
48 moodleRoot = pkgs.stdenv.mkDerivation rec {
49 name= "moodle-2.8.10";
50
51 src = pkgs.fetchurl {
52 url = "https://download.moodle.org/stable28/${name}.tgz";
53 sha256 = "0c3r5081ipcwc9s6shakllnrkd589y2ln5z5m1q09l4h6a7cy4z2";
54 };
55
56 buildPhase =
57 ''
58 '';
59
60 installPhase =
61 ''
62 mkdir -p $out
63 cp -r * $out
64 cp ${moodleConfig} $out/config.php
65 '';
66 };
67
68in
69
70{
71
72 extraConfig =
73 ''
74 # this should be config.urlPrefix instead of /
75 Alias / ${moodleRoot}/
76 <Directory ${moodleRoot}>
77 DirectoryIndex index.php
78 </Directory>
79 '';
80
81 documentRoot = moodleRoot; # TODO: fix this, should be config.urlPrefix
82
83 enablePHP = true;
84
85 options = {
86
87 id = mkOption {
88 default = "main";
89 description = ''
90 A unique identifier necessary to keep multiple Moodle server
91 instances on the same machine apart.
92 '';
93 };
94
95 dbType = mkOption {
96 default = "postgres";
97 example = "mysql";
98 description = "Database type.";
99 };
100
101 dbName = mkOption {
102 default = "moodle";
103 description = "Name of the database that holds the Moodle data.";
104 };
105
106 dbHost = mkOption {
107 default = "localhost";
108 example = "10.0.2.2";
109 description = ''
110 The location of the database server.
111 '';
112 };
113
114 dbPort = mkOption {
115 default = ""; # use the default port
116 example = "12345";
117 description = ''
118 The port that is used to connect to the database server.
119 '';
120 };
121
122 dbUser = mkOption {
123 default = "moodle";
124 description = "The user name for accessing the database.";
125 };
126
127 dbPassword = mkOption {
128 default = "";
129 example = "password";
130 description = ''
131 The password of the database user. Warning: this is stored in
132 cleartext in the Nix store!
133 '';
134 };
135
136 dbPrefix = mkOption {
137 default = "mdl_";
138 example = "my_other_mdl_";
139 description = ''
140 A prefix for each table, if multiple moodles should run in a single database.
141 '';
142 };
143
144 wwwRoot = mkOption {
145 type = types.string;
146 example = "http://my.machine.com/my-moodle";
147 description = ''
148 The full web address where moodle has been installed.
149 '';
150 };
151
152 dataRoot = mkOption {
153 default = "/var/lib/moodledata";
154 example = "/var/lib/moodledata";
155 description = ''
156 The data directory for moodle. Needs to be writable!
157 '';
158 type = types.path;
159 };
160
161
162 extraConfig = mkOption {
163 default = "";
164 example =
165 ''
166 '';
167 description = ''
168 Any additional text to be appended to Moodle's
169 configuration file. This is a PHP script.
170 '';
171 };
172
173 debug = {
174 noEmailEver = mkOption {
175 default = false;
176 example = "true";
177 description = ''
178 Set this to true to prevent Moodle from ever sending any email.
179 '';
180 };
181 };
182 };
183
184 startupScript = pkgs.writeScript "moodle_startup.sh" ''
185 echo "Checking for existence of ${config.dataRoot}"
186 if [ ! -e "${config.dataRoot}" ]
187 then
188 mkdir -p "${config.dataRoot}"
189 chown ${serverInfo.serverConfig.user}.${serverInfo.serverConfig.group} "${config.dataRoot}"
190 fi
191 '';
192
193}