From 41ae4d1af9a2273a1925cfe755989ee7f76e8adb Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Sat, 7 Feb 2015 21:20:53 +0100 Subject: [PATCH] add limesurvey package and nixos module --- .../web-servers/apache-httpd/limesurvey.nix | 196 ++++++++++++++++++ pkgs/servers/limesurvey/default.nix | 41 ++++ pkgs/top-level/all-packages.nix | 2 + 3 files changed, 239 insertions(+) create mode 100644 nixos/modules/services/web-servers/apache-httpd/limesurvey.nix create mode 100644 pkgs/servers/limesurvey/default.nix diff --git a/nixos/modules/services/web-servers/apache-httpd/limesurvey.nix b/nixos/modules/services/web-servers/apache-httpd/limesurvey.nix new file mode 100644 index 000000000000..6f1f67970f6c --- /dev/null +++ b/nixos/modules/services/web-servers/apache-httpd/limesurvey.nix @@ -0,0 +1,196 @@ +{ config, lib, pkgs, serverInfo, php, ... }: + +with lib; + +let + + httpd = serverInfo.serverConfig.package; + + version24 = !versionOlder httpd.version "2.4"; + + allGranted = if version24 then '' + Require all granted + '' else '' + Order allow,deny + Allow from all + ''; + + limesurveyConfig = pkgs.writeText "config.php" '' + + ''; + + limesurveyRoot = "${pkgs.limesurvey}/share/limesurvey/"; + +in rec { + + extraConfig = '' + Alias ${config.urlPrefix}/tmp ${config.dataDir}/tmp + + + ${allGranted} + Options -Indexes +FollowSymlinks + + + Alias ${config.urlPrefix}/upload ${config.dataDir}/upload + + + ${allGranted} + Options -Indexes + + + ${if config.urlPrefix != "" then '' + Alias ${config.urlPrefix} ${limesurveyRoot} + '' else '' + RewriteEngine On + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d + ''} + + + DirectoryIndex index.php + + ''; + + globalEnvVars = [ + { name = "LIMESURVEY_CONFIG"; value = limesurveyConfig; } + ]; + + documentRoot = if config.urlPrefix == "" then limesurveyRoot else null; + + enablePHP = true; + + options = { + + id = mkOption { + default = "main"; + description = '' + 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. + ''; + }; + + urlPrefix = mkOption { + default = ""; + description = "Url prefix for site."; + type = types.str; + }; + + dbType = mkOption { + default = "pgsql"; + description = "Type of database for limesurvey, for now, only pgsql."; + type = types.enum ["pgsql"]; + }; + + dbName = mkOption { + default = "limesurvey"; + description = "Name of the database that holds the limesurvey data."; + type = types.str; + }; + + dbHost = mkOption { + default = "localhost"; + description = "Limesurvey database host."; + type = types.str; + }; + + dbPort = mkOption { + default = 5432; + description = "Limesurvey database port."; + type = types.int; + }; + + dbUser = mkOption { + default = "limesurvey"; + description = "Limesurvey database user."; + type = types.str; + }; + + dbPassword = mkOption { + example = "foobar"; + description = "Limesurvey database password."; + type = types.str; + }; + + adminUser = mkOption { + description = "Limesurvey admin username."; + default = "admin"; + type = types.str; + }; + + adminPassword = mkOption { + description = "Default limesurvey admin password."; + default = "admin"; + type = types.str; + }; + + adminEmail = mkOption { + description = "Limesurvey admin email."; + default = "admin@admin.com"; + type = types.str; + }; + + forceSSL = mkOption { + default = false; + description = "Force use of HTTPS connection."; + type = types.bool; + }; + + siteName = mkOption { + default = "LimeSurvey"; + description = "LimeSurvey name of the site."; + type = types.str; + }; + + defaultLang = mkOption { + default = "en"; + description = "LimeSurvey default language."; + type = types.str; + }; + + dataDir = mkOption { + default = "/var/lib/limesurvey"; + description = "LimeSurvey data directory."; + type = types.path; + }; + }; + + 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 + fi + ''; +} diff --git a/pkgs/servers/limesurvey/default.nix b/pkgs/servers/limesurvey/default.nix new file mode 100644 index 000000000000..89ce5a644d80 --- /dev/null +++ b/pkgs/servers/limesurvey/default.nix @@ -0,0 +1,41 @@ +{ stdenv, lib, fetchFromGitHub, writeText, makeWrapper, php }: + +stdenv.mkDerivation rec { + name = "limesurvey-${version}"; + version = "2.05_plus_141210"; + + src = fetchFromGitHub { + owner = "LimeSurvey"; + repo = "LimeSurvey"; + rev = version; + sha256 = "1b5yixrlrjm055ag07c7phk84mk1892v20nsss1y0xzvgn6s14gq"; + }; + + buildInputs = [ makeWrapper ]; + + phpConfig = writeText "config.php" '' + + ''; + + patchPhase = '' + substituteInPlace application/core/LSYii_Application.php \ + --replace "'basePath" "//'basePath" + ''; + + installPhase = '' + mkdir -p $out/{bin,share/limesurvey} + cp -R . $out/share/limesurvey + cp ${phpConfig} $out/share/limesurvey/application/config/config.php + makeWrapper ${php}/bin/php $out/bin/limesurvey-console \ + --add-flags "$out/share/limesurvey/application/commands/console.php" + ''; + + meta = with lib; { + description = "Open source survey application"; + license = licenses.gpl2; + homepage = https://www.limesurvey.org; + maintainers = with maintainers; [offline]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 7531fbf308bb..0ec714df98c1 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1744,6 +1744,8 @@ let librdmacm = callPackage ../development/libraries/librdmacm { }; + limesurvey = callPackage ../servers/limesurvey { }; + logcheck = callPackage ../tools/system/logcheck { inherit (perlPackages) mimeConstruct; };