···
+
{ config, lib, pkgs, serverInfo, php, ... }:
+
httpd = serverInfo.serverConfig.package;
+
version24 = !versionOlder httpd.version "2.4";
+
allGranted = if version24 then ''
+
limesurveyConfig = pkgs.writeText "config.php" ''
+
$config['name'] = "${config.siteName}";
+
$config['runtimePath'] = "${config.dataDir}/tmp/runtime";
+
$config['components'] = array();
+
$config['components']['db'] = array();
+
$config['components']['db']['connectionString'] = '${config.dbType}:host=${config.dbHost};port=${toString config.dbPort};user=${config.dbUser};password=${config.dbPassword};dbname=${config.dbName};';
+
$config['components']['db']['username'] = '${config.dbUser}';
+
$config['components']['db']['password'] = '${config.dbPassword}';
+
$config['components']['db']['charset'] = 'utf-8';
+
$config['components']['db']['tablePrefix'] = "prefix_";
+
$config['components']['assetManager'] = array();
+
$config['components']['assetManager']['basePath'] = '${config.dataDir}/tmp/assets';
+
$config['config'] = array();
+
$config['config']['debug'] = 1;
+
$config['config']['tempdir'] = "${config.dataDir}/tmp";
+
$config['config']['tempdir'] = "${config.dataDir}/tmp";
+
$config['config']['uploaddir'] = "${config.dataDir}/upload";
+
$config['config']['force_ssl'] = '${if config.forceSSL then "on" else ""}';
+
$config['config']['defaultlang'] = '${config.defaultLang}';
+
limesurveyRoot = "${pkgs.limesurvey}/share/limesurvey/";
+
Alias ${config.urlPrefix}/tmp ${config.dataDir}/tmp
+
<Directory ${config.dataDir}/tmp>
+
Options -Indexes +FollowSymlinks
+
Alias ${config.urlPrefix}/upload ${config.dataDir}/upload
+
<Directory ${config.dataDir}/upload>
+
${if config.urlPrefix != "" then ''
+
Alias ${config.urlPrefix} ${limesurveyRoot}
+
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
+
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
+
<Directory ${limesurveyRoot}>
+
DirectoryIndex index.php
+
{ name = "LIMESURVEY_CONFIG"; value = limesurveyConfig; }
+
documentRoot = if config.urlPrefix == "" then limesurveyRoot else null;
+
A unique identifier necessary to keep multiple owncloud server
+
instances on the same machine apart. This is used to
+
disambiguate the administrative scripts, which get names like
+
mediawiki-$id-change-password.
+
description = "Url prefix for site.";
+
description = "Type of database for limesurvey, for now, only pgsql.";
+
type = types.enum ["pgsql"];
+
default = "limesurvey";
+
description = "Name of the database that holds the limesurvey data.";
+
description = "Limesurvey database host.";
+
description = "Limesurvey database port.";
+
default = "limesurvey";
+
description = "Limesurvey database user.";
+
dbPassword = mkOption {
+
description = "Limesurvey database password.";
+
description = "Limesurvey admin username.";
+
adminPassword = mkOption {
+
description = "Default limesurvey admin password.";
+
adminEmail = mkOption {
+
description = "Limesurvey admin email.";
+
default = "admin@admin.com";
+
description = "Force use of HTTPS connection.";
+
default = "LimeSurvey";
+
description = "LimeSurvey name of the site.";
+
defaultLang = mkOption {
+
description = "LimeSurvey default language.";
+
default = "/var/lib/limesurvey";
+
description = "LimeSurvey data directory.";
+
startupScript = pkgs.writeScript "limesurvey_startup.sh" ''
+
if [ ! -f ${config.dataDir}/.created ]; then
+
mkdir -p ${config.dataDir}/{tmp/runtime,tmp/assets,tmp/upload,upload}
+
chmod -R ug+rw ${config.dataDir}
+
chmod -R o-rwx ${config.dataDir}
+
chown -R wwwrun:wwwrun ${config.dataDir}
+
${pkgs.postgresql}/bin/createuser --no-superuser --no-createdb --no-createrole "${config.dbUser}" || true
+
${pkgs.postgresql}/bin/createdb "${config.dbName}" -O "${config.dbUser}" || true
+
${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/psql -U postgres -d postgres -c "alter user ${config.dbUser} with password '${config.dbPassword}';" || true
+
${pkgs.limesurvey}/bin/limesurvey-console install '${config.adminUser}' '${config.adminPassword}' '${config.adminUser}' '${config.adminEmail}'
+
touch ${config.dataDir}/.created