···
1
+
{ config, lib, pkgs, serverInfo, php, ... }:
7
+
httpd = serverInfo.serverConfig.package;
9
+
version24 = !versionOlder httpd.version "2.4";
11
+
allGranted = if version24 then ''
18
+
limesurveyConfig = pkgs.writeText "config.php" ''
21
+
$config['name'] = "${config.siteName}";
22
+
$config['runtimePath'] = "${config.dataDir}/tmp/runtime";
23
+
$config['components'] = array();
24
+
$config['components']['db'] = array();
25
+
$config['components']['db']['connectionString'] = '${config.dbType}:host=${config.dbHost};port=${toString config.dbPort};user=${config.dbUser};password=${config.dbPassword};dbname=${config.dbName};';
26
+
$config['components']['db']['username'] = '${config.dbUser}';
27
+
$config['components']['db']['password'] = '${config.dbPassword}';
28
+
$config['components']['db']['charset'] = 'utf-8';
29
+
$config['components']['db']['tablePrefix'] = "prefix_";
30
+
$config['components']['assetManager'] = array();
31
+
$config['components']['assetManager']['basePath'] = '${config.dataDir}/tmp/assets';
32
+
$config['config'] = array();
33
+
$config['config']['debug'] = 1;
34
+
$config['config']['tempdir'] = "${config.dataDir}/tmp";
35
+
$config['config']['tempdir'] = "${config.dataDir}/tmp";
36
+
$config['config']['uploaddir'] = "${config.dataDir}/upload";
37
+
$config['config']['force_ssl'] = '${if config.forceSSL then "on" else ""}';
38
+
$config['config']['defaultlang'] = '${config.defaultLang}';
43
+
limesurveyRoot = "${pkgs.limesurvey}/share/limesurvey/";
48
+
Alias ${config.urlPrefix}/tmp ${config.dataDir}/tmp
50
+
<Directory ${config.dataDir}/tmp>
52
+
Options -Indexes +FollowSymlinks
55
+
Alias ${config.urlPrefix}/upload ${config.dataDir}/upload
57
+
<Directory ${config.dataDir}/upload>
62
+
${if config.urlPrefix != "" then ''
63
+
Alias ${config.urlPrefix} ${limesurveyRoot}
66
+
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
67
+
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
70
+
<Directory ${limesurveyRoot}>
71
+
DirectoryIndex index.php
76
+
{ name = "LIMESURVEY_CONFIG"; value = limesurveyConfig; }
79
+
documentRoot = if config.urlPrefix == "" then limesurveyRoot else null;
88
+
A unique identifier necessary to keep multiple owncloud server
89
+
instances on the same machine apart. This is used to
90
+
disambiguate the administrative scripts, which get names like
91
+
mediawiki-$id-change-password.
95
+
urlPrefix = mkOption {
97
+
description = "Url prefix for site.";
101
+
dbType = mkOption {
103
+
description = "Type of database for limesurvey, for now, only pgsql.";
104
+
type = types.enum ["pgsql"];
107
+
dbName = mkOption {
108
+
default = "limesurvey";
109
+
description = "Name of the database that holds the limesurvey data.";
113
+
dbHost = mkOption {
114
+
default = "localhost";
115
+
description = "Limesurvey database host.";
119
+
dbPort = mkOption {
121
+
description = "Limesurvey database port.";
125
+
dbUser = mkOption {
126
+
default = "limesurvey";
127
+
description = "Limesurvey database user.";
131
+
dbPassword = mkOption {
132
+
example = "foobar";
133
+
description = "Limesurvey database password.";
137
+
adminUser = mkOption {
138
+
description = "Limesurvey admin username.";
143
+
adminPassword = mkOption {
144
+
description = "Default limesurvey admin password.";
149
+
adminEmail = mkOption {
150
+
description = "Limesurvey admin email.";
151
+
default = "admin@admin.com";
155
+
forceSSL = mkOption {
157
+
description = "Force use of HTTPS connection.";
161
+
siteName = mkOption {
162
+
default = "LimeSurvey";
163
+
description = "LimeSurvey name of the site.";
167
+
defaultLang = mkOption {
169
+
description = "LimeSurvey default language.";
173
+
dataDir = mkOption {
174
+
default = "/var/lib/limesurvey";
175
+
description = "LimeSurvey data directory.";
180
+
startupScript = pkgs.writeScript "limesurvey_startup.sh" ''
181
+
if [ ! -f ${config.dataDir}/.created ]; then
182
+
mkdir -p ${config.dataDir}/{tmp/runtime,tmp/assets,tmp/upload,upload}
183
+
chmod -R ug+rw ${config.dataDir}
184
+
chmod -R o-rwx ${config.dataDir}
185
+
chown -R wwwrun:wwwrun ${config.dataDir}
187
+
${pkgs.postgresql}/bin/createuser --no-superuser --no-createdb --no-createrole "${config.dbUser}" || true
188
+
${pkgs.postgresql}/bin/createdb "${config.dbName}" -O "${config.dbUser}" || true
189
+
${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/psql -U postgres -d postgres -c "alter user ${config.dbUser} with password '${config.dbPassword}';" || true
191
+
${pkgs.limesurvey}/bin/limesurvey-console install '${config.adminUser}' '${config.adminPassword}' '${config.adminUser}' '${config.adminEmail}'
193
+
touch ${config.dataDir}/.created