at 17.09-beta 5.7 kB view raw
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 limesurveyConfig = pkgs.writeText "config.php" '' 19 <?php 20 $config = array(); 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}'; 39 return $config; 40 ?> 41 ''; 42 43 limesurveyRoot = "${pkgs.limesurvey}/share/limesurvey/"; 44 45in rec { 46 47 extraConfig = '' 48 Alias ${config.urlPrefix}/tmp ${config.dataDir}/tmp 49 50 <Directory ${config.dataDir}/tmp> 51 ${allGranted} 52 Options -Indexes +FollowSymlinks 53 </Directory> 54 55 Alias ${config.urlPrefix}/upload ${config.dataDir}/upload 56 57 <Directory ${config.dataDir}/upload> 58 ${allGranted} 59 Options -Indexes 60 </Directory> 61 62 ${if config.urlPrefix != "" then '' 63 Alias ${config.urlPrefix} ${limesurveyRoot} 64 '' else '' 65 RewriteEngine On 66 RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f 67 RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d 68 ''} 69 70 <Directory ${limesurveyRoot}> 71 DirectoryIndex index.php 72 </Directory> 73 ''; 74 75 globalEnvVars = [ 76 { name = "LIMESURVEY_CONFIG"; value = limesurveyConfig; } 77 ]; 78 79 documentRoot = if config.urlPrefix == "" then limesurveyRoot else null; 80 81 enablePHP = true; 82 83 options = { 84 85 id = mkOption { 86 default = "main"; 87 description = '' 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. 92 ''; 93 }; 94 95 urlPrefix = mkOption { 96 default = ""; 97 description = "Url prefix for site."; 98 type = types.str; 99 }; 100 101 dbType = mkOption { 102 default = "pgsql"; 103 description = "Type of database for limesurvey, for now, only pgsql."; 104 type = types.enum ["pgsql"]; 105 }; 106 107 dbName = mkOption { 108 default = "limesurvey"; 109 description = "Name of the database that holds the limesurvey data."; 110 type = types.str; 111 }; 112 113 dbHost = mkOption { 114 default = "localhost"; 115 description = "Limesurvey database host."; 116 type = types.str; 117 }; 118 119 dbPort = mkOption { 120 default = 5432; 121 description = "Limesurvey database port."; 122 type = types.int; 123 }; 124 125 dbUser = mkOption { 126 default = "limesurvey"; 127 description = "Limesurvey database user."; 128 type = types.str; 129 }; 130 131 dbPassword = mkOption { 132 example = "foobar"; 133 description = "Limesurvey database password."; 134 type = types.str; 135 }; 136 137 adminUser = mkOption { 138 description = "Limesurvey admin username."; 139 default = "admin"; 140 type = types.str; 141 }; 142 143 adminPassword = mkOption { 144 description = "Default limesurvey admin password."; 145 default = "admin"; 146 type = types.str; 147 }; 148 149 adminEmail = mkOption { 150 description = "Limesurvey admin email."; 151 default = "admin@admin.com"; 152 type = types.str; 153 }; 154 155 forceSSL = mkOption { 156 default = false; 157 description = "Force use of HTTPS connection."; 158 type = types.bool; 159 }; 160 161 siteName = mkOption { 162 default = "LimeSurvey"; 163 description = "LimeSurvey name of the site."; 164 type = types.str; 165 }; 166 167 defaultLang = mkOption { 168 default = "en"; 169 description = "LimeSurvey default language."; 170 type = types.str; 171 }; 172 173 dataDir = mkOption { 174 default = "/var/lib/limesurvey"; 175 description = "LimeSurvey data directory."; 176 type = types.path; 177 }; 178 }; 179 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} 186 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 190 191 ${pkgs.limesurvey}/bin/limesurvey-console install '${config.adminUser}' '${config.adminPassword}' '${config.adminUser}' '${config.adminEmail}' 192 193 touch ${config.dataDir}/.created 194 fi 195 ''; 196}