nixos/limesurvey: allow package to be customized

This commit is contained in:
Julien Malka 2024-04-15 19:55:19 +02:00
parent fc69edccf5
commit 873db98d3d
No known key found for this signature in database
GPG Key ID: 6FC74C847011FD83

View File

@ -2,7 +2,7 @@
let let
inherit (lib) mkDefault mkEnableOption mkForce mkIf mkMerge mkOption; inherit (lib) mkDefault mkEnableOption mkForce mkIf mkMerge mkOption mkPackageOption;
inherit (lib) literalExpression mapAttrs optional optionalString types; inherit (lib) literalExpression mapAttrs optional optionalString types;
cfg = config.services.limesurvey; cfg = config.services.limesurvey;
@ -12,8 +12,6 @@ let
group = config.services.httpd.group; group = config.services.httpd.group;
stateDir = "/var/lib/limesurvey"; stateDir = "/var/lib/limesurvey";
pkg = pkgs.limesurvey;
configType = with types; oneOf [ (attrsOf configType) str int bool ] // { configType = with types; oneOf [ (attrsOf configType) str int bool ] // {
description = "limesurvey config type (str, int, bool or attribute set thereof)"; description = "limesurvey config type (str, int, bool or attribute set thereof)";
}; };
@ -34,6 +32,8 @@ in
options.services.limesurvey = { options.services.limesurvey = {
enable = mkEnableOption "Limesurvey web application"; enable = mkEnableOption "Limesurvey web application";
package = mkPackageOption pkgs "limesurvey" { };
encryptionKey = mkOption { encryptionKey = mkOption {
type = types.str; type = types.str;
default = "E17687FC77CEE247F0E22BB3ECF27FDE8BEC310A892347EC13013ABA11AA7EB5"; default = "E17687FC77CEE247F0E22BB3ECF27FDE8BEC310A892347EC13013ABA11AA7EB5";
@ -240,7 +240,7 @@ in
adminAddr = mkDefault cfg.virtualHost.adminAddr; adminAddr = mkDefault cfg.virtualHost.adminAddr;
extraModules = [ "proxy_fcgi" ]; extraModules = [ "proxy_fcgi" ];
virtualHosts.${cfg.virtualHost.hostName} = mkMerge [ cfg.virtualHost { virtualHosts.${cfg.virtualHost.hostName} = mkMerge [ cfg.virtualHost {
documentRoot = mkForce "${pkg}/share/limesurvey"; documentRoot = mkForce "${cfg.package}/share/limesurvey";
extraConfig = '' extraConfig = ''
Alias "/tmp" "${stateDir}/tmp" Alias "/tmp" "${stateDir}/tmp"
<Directory "${stateDir}"> <Directory "${stateDir}">
@ -256,7 +256,7 @@ in
Options -Indexes Options -Indexes
</Directory> </Directory>
<Directory "${pkg}/share/limesurvey"> <Directory "${cfg.package}/share/limesurvey">
<FilesMatch "\.php$"> <FilesMatch "\.php$">
<If "-f %{REQUEST_FILENAME}"> <If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/" SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
@ -277,7 +277,7 @@ in
"d ${stateDir}/tmp/assets 0750 ${user} ${group} - -" "d ${stateDir}/tmp/assets 0750 ${user} ${group} - -"
"d ${stateDir}/tmp/runtime 0750 ${user} ${group} - -" "d ${stateDir}/tmp/runtime 0750 ${user} ${group} - -"
"d ${stateDir}/tmp/upload 0750 ${user} ${group} - -" "d ${stateDir}/tmp/upload 0750 ${user} ${group} - -"
"C ${stateDir}/upload 0750 ${user} ${group} - ${pkg}/share/limesurvey/upload" "C ${stateDir}/upload 0750 ${user} ${group} - ${cfg.package}/share/limesurvey/upload"
]; ];
systemd.services.limesurvey-init = { systemd.services.limesurvey-init = {
@ -288,8 +288,8 @@ in
environment.LIMESURVEY_CONFIG = limesurveyConfig; environment.LIMESURVEY_CONFIG = limesurveyConfig;
script = '' script = ''
# update or install the database as required # update or install the database as required
${pkgs.php81}/bin/php ${pkg}/share/limesurvey/application/commands/console.php updatedb || \ ${pkgs.php81}/bin/php ${cfg.package}/share/limesurvey/application/commands/console.php updatedb || \
${pkgs.php81}/bin/php ${pkg}/share/limesurvey/application/commands/console.php install admin password admin admin@example.com verbose ${pkgs.php81}/bin/php ${cfg.package}/share/limesurvey/application/commands/console.php install admin password admin admin@example.com verbose
''; '';
serviceConfig = { serviceConfig = {
User = user; User = user;