9 cfg = config.services.pretalx;
10 format = pkgs.formats.ini { };
12 configFile = format.generate "pretalx.cfg" cfg.settings;
14 finalPackage = cfg.package.override {
15 inherit (cfg) plugins;
18 pythonEnv = finalPackage.python.buildEnv.override {
19 extraLibs = with finalPackage.python.pkgs; [
20 (toPythonModule finalPackage)
23 ++ finalPackage.optional-dependencies.redis
24 ++ lib.optionals cfg.celery.enable [ celery ]
25 ++ lib.optionals (cfg.settings.database.backend == "mysql") finalPackage.optional-dependencies.mysql
26 ++ lib.optionals (cfg.settings.database.backend == "postgresql") finalPackage.optional-dependencies.postgres;
32 maintainers = with maintainers; [ hexa] ++ teams.c3d2.members;
35 options.services.pretalx = {
36 enable = lib.mkEnableOption "pretalx";
38 package = lib.mkPackageOption pkgs "pretalx" {};
40 group = lib.mkOption {
43 description = "Group under which pretalx should run.";
49 description = "User under which pretalx should run.";
52 plugins = lib.mkOption {
53 type = with lib.types; listOf package;
55 example = lib.literalExpression ''
56 with config.services.pretalx.package.plugins; [
62 Pretalx plugins to install into the Python environment.
66 gunicorn.extraArgs = lib.mkOption {
67 type = with lib.types; listOf str;
75 "--max-requests-jitter=50"
79 Extra arguments to pass to gunicorn.
80 See <https://docs.pretalx.org/administrator/installation.html#step-6-starting-pretalx-as-a-service> for details.
82 apply = lib.escapeShellArgs;
86 enable = lib.mkOption {
87 type = lib.types.bool;
91 Whether to set up celery as an asynchronous task runner.
95 extraArgs = lib.mkOption {
96 type = with lib.types; listOf str;
99 Extra arguments to pass to celery.
101 See <https://docs.celeryq.dev/en/stable/reference/cli.html#celery-worker> for more info.
103 apply = utils.escapeSystemdExecArgs;
108 enable = lib.mkOption {
109 type = lib.types.bool;
113 Whether to set up an nginx virtual host.
117 domain = lib.mkOption {
118 type = lib.types.str;
119 example = "talks.example.com";
121 The domain name under which to set up the virtual host.
126 database.createLocally = lib.mkOption {
127 type = lib.types.bool;
131 Whether to automatically set up the database on the local DBMS instance.
133 Currently only supported for PostgreSQL. Not required for sqlite.
137 settings = lib.mkOption {
138 type = lib.types.submodule {
139 freeformType = format.type;
142 backend = lib.mkOption {
143 type = lib.types.enum [
146 default = "postgresql";
148 Database backend to use.
150 Currently only PostgreSQL gets tested, and as such we don't support any other DBMS.
152 readOnly = true; # only postgres supported right now
155 host = lib.mkOption {
156 type = with lib.types; nullOr types.path;
157 default = if cfg.settings.database.backend == "postgresql" then "/run/postgresql"
158 else if cfg.settings.database.backend == "mysql" then "/run/mysqld/mysqld.sock"
160 defaultText = lib.literalExpression ''
161 if config.services.pretalx.settings..database.backend == "postgresql" then "/run/postgresql"
162 else if config.services.pretalx.settings.database.backend == "mysql" then "/run/mysqld/mysqld.sock"
166 Database host or socket path.
170 name = lib.mkOption {
171 type = lib.types.str;
178 user = lib.mkOption {
179 type = lib.types.str;
188 data = lib.mkOption {
189 type = lib.types.path;
190 default = "/var/lib/pretalx";
192 Base path for all other storage paths.
195 logs = lib.mkOption {
196 type = lib.types.path;
197 default = "/var/log/pretalx";
199 Path to the log directory, that pretalx logs message to.
202 static = lib.mkOption {
203 type = lib.types.path;
204 default = "${cfg.package.static}/";
205 defaultText = lib.literalExpression "\${config.services.pretalx.package}.static}/";
208 Path to the directory that contains static files.
214 backend = lib.mkOption {
215 type = with lib.types; nullOr str;
216 default = lib.optionalString cfg.celery.enable "redis+socket://${config.services.redis.servers.pretalx.unixSocket}?virtual_host=1";
217 defaultText = lib.literalExpression ''
218 optionalString config.services.pretalx.celery.enable "redis+socket://''${config.services.redis.servers.pretalx.unixSocket}?virtual_host=1"
221 URI to the celery backend used for the asynchronous job queue.
225 broker = lib.mkOption {
226 type = with lib.types; nullOr str;
227 default = lib.optionalString cfg.celery.enable "redis+socket://${config.services.redis.servers.pretalx.unixSocket}?virtual_host=2";
228 defaultText = lib.literalExpression ''
229 optionalString config.services.pretalx.celery.enable "redis+socket://''${config.services.redis.servers.pretalx.unixSocket}?virtual_host=2"
232 URI to the celery broker used for the asynchronous job queue.
238 location = lib.mkOption {
239 type = with lib.types; nullOr str;
240 default = "unix://${config.services.redis.servers.pretalx.unixSocket}?db=0";
241 defaultText = lib.literalExpression ''
242 "unix://''${config.services.redis.servers.pretalx.unixSocket}?db=0"
245 URI to the redis server, used to speed up locking, caching and session storage.
249 session = lib.mkOption {
250 type = lib.types.bool;
254 Whether to use redis as the session storage.
261 type = lib.types.str;
262 default = "https://${cfg.nginx.domain}";
263 defaultText = lib.literalExpression "https://\${config.services.pretalx.nginx.domain}";
264 example = "https://talks.example.com";
266 The base URI below which your pretalx instance will be reachable.
274 pretalx configuration as a Nix attribute set. All settings can also be passed
275 from the environment.
277 See <https://docs.pretalx.org/administrator/configure.html> for possible options.
282 config = lib.mkIf cfg.enable {
283 # https://docs.pretalx.org/administrator/installation.html
285 environment.systemPackages = [
286 (pkgs.writeScriptBin "pretalx-manage" ''
287 cd ${cfg.settings.filesystem.data}
289 if [[ "$USER" != ${cfg.user} ]]; then
290 sudo='exec /run/wrappers/bin/sudo -u ${cfg.user} --preserve-env=PRETALX_CONFIG_FILE'
292 export PRETALX_CONFIG_FILE=${configFile}
293 $sudo ${lib.getExe' pythonEnv "pretalx-manage"} "$@"
297 services.logrotate.settings.pretalx = {
298 files = "${cfg.settings.filesystem.logs}/*.log";
299 su = "${cfg.user} ${cfg.group}";
300 frequency = "weekly";
307 nginx = lib.mkIf cfg.nginx.enable {
309 recommendedGzipSettings = lib.mkDefault true;
310 recommendedOptimisation = lib.mkDefault true;
311 recommendedProxySettings = lib.mkDefault true;
312 recommendedTlsSettings = lib.mkDefault true;
313 upstreams.pretalx.servers."unix:/run/pretalx/pretalx.sock" = { };
314 virtualHosts.${cfg.nginx.domain} = {
315 # https://docs.pretalx.org/administrator/installation.html#step-7-ssl
317 more_set_headers "Referrer-Policy: same-origin";
318 more_set_headers "X-Content-Type-Options: nosniff";
321 "/".proxyPass = "http://pretalx";
323 alias = "${cfg.settings.filesystem.data}/media/";
326 more_set_headers 'Content-Disposition: attachment; filename="$1"';
331 alias = cfg.settings.filesystem.static;
334 more_set_headers Cache-Control "public";
342 postgresql = lib.mkIf (cfg.database.createLocally && cfg.settings.database.backend == "postgresql") {
345 name = cfg.settings.database.user;
346 ensureDBOwnership = true;
348 ensureDatabases = [ cfg.settings.database.name ];
351 redis.servers.pretalx.enable = true;
354 systemd.services = let
356 environment.PRETALX_CONFIG_FILE = configFile;
364 StateDirectoryMode = "0750";
365 LogsDirectory = "pretalx";
366 WorkingDirectory = cfg.settings.filesystem.data;
367 SupplementaryGroups = [ "redis-pretalx" ];
368 AmbientCapabilities = "";
369 CapabilityBoundingSet = [ "" ];
370 DevicePolicy = "closed";
371 LockPersonality = true;
372 MemoryDenyWriteExecute = true;
373 NoNewPrivileges = true;
374 PrivateDevices = true;
377 ProtectControlGroups = true;
379 ProtectHostname = true;
380 ProtectKernelLogs = true;
381 ProtectKernelModules = true;
382 ProtectKernelTunables = true;
383 ProtectProc = "invisible";
384 ProtectSystem = "strict";
386 RestrictAddressFamilies = [
391 RestrictNamespaces = true;
392 RestrictRealtime = true;
393 RestrictSUIDSGID = true;
394 SystemCallArchitectures = "native";
404 pretalx-web = lib.recursiveUpdate commonUnitConfig {
405 description = "pretalx web service";
408 "redis-pretalx.service"
409 ] ++ lib.optionals (cfg.settings.database.backend == "postgresql") [
411 ] ++ lib.optionals (cfg.settings.database.backend == "mysql") [
414 wantedBy = [ "multi-user.target" ];
416 versionFile="${cfg.settings.filesystem.data}/.version"
417 version=$(cat "$versionFile" 2>/dev/null || echo 0)
419 if [[ $version != ${cfg.package.version} ]]; then
420 ${lib.getExe' pythonEnv "pretalx-manage"} migrate
422 echo "${cfg.package.version}" > "$versionFile"
426 ExecStart = "${lib.getExe' pythonEnv "gunicorn"} --bind unix:/run/pretalx/pretalx.sock ${cfg.gunicorn.extraArgs} pretalx.wsgi";
427 RuntimeDirectory = "pretalx";
431 pretalx-periodic = lib.recursiveUpdate commonUnitConfig {
432 description = "pretalx periodic task runner";
434 startAt = [ "*:3,18,33,48" ];
437 ExecStart = "${lib.getExe' pythonEnv "pretalx-manage"} runperiodic";
441 pretalx-clear-sessions = lib.recursiveUpdate commonUnitConfig {
442 description = "pretalx session pruning";
443 startAt = [ "monthly" ];
446 ExecStart = "${lib.getExe' pythonEnv "pretalx-manage"} clearsessions";
450 pretalx-worker = lib.mkIf cfg.celery.enable (lib.recursiveUpdate commonUnitConfig {
451 description = "pretalx asynchronous job runner";
454 "redis-pretalx.service"
455 ] ++ lib.optionals (cfg.settings.database.backend == "postgresql") [
457 ] ++ lib.optionals (cfg.settings.database.backend == "mysql") [
460 wantedBy = [ "multi-user.target" ];
461 serviceConfig.ExecStart = "${lib.getExe' pythonEnv "celery"} -A pretalx.celery_app worker ${cfg.celery.extraArgs}";
464 nginx.serviceConfig.SupplementaryGroups = lib.mkIf cfg.nginx.enable [ "pretalx" ];
467 systemd.sockets.pretalx-web.socketConfig = {
468 ListenStream = "/run/pretalx/pretalx.sock";
469 SocketUser = "nginx";
473 groups.${cfg.group} = {};
474 users.${cfg.user} = {