git.iko.soy/typeable/nixpkgs
on master help sign in
add limesurvey package and nixos module
commit41ae4d1af9a2273a1925cfe755989ee7f76e8adb authorJaka Hudoklin <jakahudoklin@gmail.com> dateSat 7 Feb 2015, 21:20 (12 years ago) parenta6a9d81
3 files changed+239
nixos/modules/services/web-servers/apache-httpd/limesurvey.nix+196 pkgs/servers/limesurvey/default.nix+41 pkgs/top-level/all-packages.nix+2
nixos/modules/services/web-servers/apache-httpd/limesurvey.nixnew file+196
@@ -0,0 +1,196 @@
1+{ config, lib, pkgs, serverInfo, php, ... }:
2+
3+with lib;
4+
5+let
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+
45+in 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+}
pkgs/servers/limesurvey/default.nixnew file+41
@@ -0,0 +1,41 @@
1+{ stdenv, lib, fetchFromGitHub, writeText, makeWrapper, php }:
2+
3+stdenv.mkDerivation rec {
4+ name = "limesurvey-${version}";
5+ version = "2.05_plus_141210";
6+
7+ src = fetchFromGitHub {
8+ owner = "LimeSurvey";
9+ repo = "LimeSurvey";
10+ rev = version;
11+ sha256 = "1b5yixrlrjm055ag07c7phk84mk1892v20nsss1y0xzvgn6s14gq";
12+ };
13+
14+ buildInputs = [ makeWrapper ];
15+
16+ phpConfig = writeText "config.php" ''
17+ <?php
18+ return require(getenv('LIMESURVEY_CONFIG'));
19+ ?>
20+ '';
21+
22+ patchPhase = ''
23+ substituteInPlace application/core/LSYii_Application.php \
24+ --replace "'basePath" "//'basePath"
25+ '';
26+
27+ installPhase = ''
28+ mkdir -p $out/{bin,share/limesurvey}
29+ cp -R . $out/share/limesurvey
30+ cp ${phpConfig} $out/share/limesurvey/application/config/config.php
31+ makeWrapper ${php}/bin/php $out/bin/limesurvey-console \
32+ --add-flags "$out/share/limesurvey/application/commands/console.php"
33+ '';
34+
35+ meta = with lib; {
36+ description = "Open source survey application";
37+ license = licenses.gpl2;
38+ homepage = https://www.limesurvey.org;
39+ maintainers = with maintainers; [offline];
40+ };
41+}
pkgs/top-level/all-packages.nix+2
@@ -1744,6 +1744,8 @@ let
17441744
17451745 librdmacm = callPackage ../development/libraries/librdmacm { };
17461746
1747+ limesurvey = callPackage ../servers/limesurvey { };
1748+
17471749 logcheck = callPackage ../tools/system/logcheck {
17481750 inherit (perlPackages) mimeConstruct;
17491751 };