Skip to content

Commit

Permalink
pretalx: Change packaging from poetry2nix to buildPythonApplication.
Browse files Browse the repository at this point in the history
Improve packaging with changes from `nixpkgs` `pretalx` PR:
<NixOS/nixpkgs#231684>

Co-authored-by: Andres Navarro <git@andresnav.com>
Co-authored-by: Ivan Mincik <ivan.mincik@gmail.com>
Co-authored-by: kubaneko <kubanek0ondrej@gmail.com>
Co-authored-by: Lorenz Leutgeb <lorenz@leutgeb.xyz>
  • Loading branch information
5 people committed Sep 11, 2023
1 parent ca1dcd5 commit 36892fe
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 1,707 deletions.
47 changes: 29 additions & 18 deletions all-packages.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{newScope, ...}: let
self = rec {
{
newScope,
lib,
...
}: let
self = let
pretalxPlugins = lib.recurseIntoAttrs (callPackage ./pkgs/pretalx/plugins.nix {});
in rec {
flarum = callPackage ./pkgs/flarum {};
gnunet-messenger-cli = callPackage ./pkgs/gnunet-messenger-cli {};
kikit = callPackage ./pkgs/kikit {};
Expand All @@ -13,23 +19,28 @@

libgnunetchat = callPackage ./pkgs/libgnunetchat {};
librecast = callPackage ./pkgs/librecast {inherit lcrq;};
pretalx-mysql = callPackage ./pkgs/pretalx {
withPlugins = true;
withMysql = true;
withRedis = true;
};
pretalx-postgresql = callPackage ./pkgs/pretalx {
withPlugins = true;
withPostgresql = true;
withRedis = true;
};
pretalx = callPackage ./pkgs/pretalx {
withPlugins = true;
withMysql = true;
withPostgresql = true;
withRedis = true;
withTest = true;
pretalx = callPackage ./pkgs/pretalx {};
pretalx-full = callPackage ./pkgs/pretalx {
withPlugins = [
pretalx-downstream
pretalx-media-ccc-de
pretalx-pages
pretalx-public-voting
pretalx-venueless
pretalx-vimeo
pretalx-youtube
];
};
inherit
(pretalxPlugins)
pretalx-downstream
pretalx-media-ccc-de
pretalx-pages
pretalx-public-voting
pretalx-venueless
pretalx-vimeo
pretalx-youtube
;
};

nixpkgs-candidates = {
Expand Down
6 changes: 2 additions & 4 deletions configs/pretalx/pretalx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
pkgs,
...
}: {
imports = [
./vm.nix
];
imports = [./vm.nix];

nixpkgs.hostPlatform = "x86_64-linux";

Expand Down Expand Up @@ -35,7 +33,7 @@
services = {
pretalx = {
enable = true;
package = pkgs.pretalx;
package = pkgs.pretalx-full;
nginx = {
# For a production configuration use this attribute set to configure the virtual host for pretalx.
};
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
with builtins; let
importPackages = pkgs:
import ./all-packages.nix {
inherit (pkgs) newScope;
inherit (pkgs) newScope lib;
};

importNixpkgs = system: overlays:
Expand Down
110 changes: 76 additions & 34 deletions modules/pretalx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,26 @@ with lib; let
gunicornSocket = "unix:${gunicornSocketPath}";
pretalxWebServiceName = "pretalx-web";

extras =
cfg.package.optional-dependencies.redis
++ lib.optionals (cfg.database.backend == "mysql") cfg.package.optional-dependencies.mysql
++ lib.optionals (cfg.database.backend == "postgresql") cfg.package.optional-dependencies.postgres;

PYTHONPATH = "${cfg.package.PYTHONPATH}:${cfg.package.python.pkgs.makePythonPath extras}";

pretalxWrapped =
pkgs.runCommand "pretalx-wrapper"
{nativeBuildInputs = [pkgs.makeWrapper pkgs.python3Packages.wrapPython];}
''
makeWrapper ${cfg.package}/bin/pretalx \
$out/bin/pretalx --prefix PYTHONPATH : "${PYTHONPATH}"
'';

# NOTE: This expect script might be replaced as soon as <https://github.com/pretalx/pretalx/issues/1551> is resolved.
pretalxInit = pkgs.writeScriptBin "expect-pretalx-init" ''
#! ${pkgs.expect}/bin/expect -f
set timeout 10
spawn ${cfg.package}/bin/pretalx init
spawn ${pretalxWrapped}/bin/pretalx init
log_user 0
expect "E-Mail: "
Expand All @@ -47,10 +62,6 @@ with lib; let
expect eof
'';

environmentFile = pkgs.runCommand "pretalx-environ" {
buildInputs = [cfg.package gunicorn]; # Sets PYTHONPATH in derivation
} "echo PYTHONPATH=$PYTHONPATH > $out;";

secretRecommendation = "Consider using a secret managing scheme such as `agenix` or `sops-nix` to generate this file.";
in {
options.services.pretalx = with types; {
Expand Down Expand Up @@ -128,7 +139,7 @@ in {
description = ''
Directory that contains static files. It needs to be writable by the pretalx process. pretalx will put files there.
'';
default = "${cfg.filesystem.data}/static";
default = "${cfg.package.static}";
};
};

Expand Down Expand Up @@ -288,6 +299,16 @@ in {
default = null;
example = "/run/secrets/pretalx/celery-broker";
};

extraArgs = mkOption {
type = listOf str;
default = [];
description = ''
Extra arguments to pass to celery.
See <https://docs.celeryq.dev/en/stable/reference/cli.html#celery-worker> for more info.
'';
apply = escapeShellArgs;
};
};

redis = {
Expand Down Expand Up @@ -417,7 +438,7 @@ in {
users.groups."${cfg.group}" = {};

environment.systemPackages = [
cfg.package
pretalxWrapped
];

environment.etc."pretalx/pretalx.cfg".text = let
Expand All @@ -427,9 +448,8 @@ in {
then s
else {};
pretalxCfg =
filterAttrs (n: v:
v != {}) # Removes empty attrsets, otherwise `generators.toINI` will fail.

# Removes empty attrsets, otherwise `generators.toINI` will fail.
filterAttrs (n: v: v != {})
(filterAttrsRecursive (n: v: (!(elem n hiddenNames) && v != null)) {
inherit (cfg) filesystem site database locale;

Expand All @@ -441,7 +461,24 @@ in {
in
generators.toINI {} (recursiveUpdate pretalxCfg cfg.extraConfig);

systemd = {
systemd = let
commonUnitConfig = {
serviceConfig = {
User = cfg.user;
Group = cfg.group;
StateDirectory = "pretalx";
LogsDirectory = "pretalx";
WorkingDirectory = libDir;
RuntimeDirectory = "pretalx";
SupplementaryGroups = ["redis-pretalx"];
};
after =
[]
++ lib.optionals cfg.redis.enable ["redis-pretalx.service"]
++ lib.optionals (cfg.database.backend == "postgresql") ["postgresql.service"]
++ lib.optionals (cfg.database.backend == "mysql") ["mysql.service"];
};
in {
sockets."pretalx-web" = {
listenStreams = [gunicornSocketPath];
socketConfig.SocketUser = config.services.nginx.user;
Expand All @@ -456,43 +493,38 @@ in {
++ optional (cfg.site.secretFile != null) (catFile "SECRET_KEY" cfg.site.secretFile)
++ optional cfg.celery.enable ''
${catFile "PRETALX_CELERY_BACKEND" cfg.celery.backendFile}
${catFile "RESULT_BACKEND" cfg.celery.brokerFile}
${catFile "PRETALX_CELERY_BROKER" cfg.celery.brokerFile}
${catFile "BROKER_URL" cfg.celery.brokerFile}
'');
oneshotServiceConfig = {
Type = "oneshot";
EnvironmentFile = environmentFile;
User = cfg.user;
Group = cfg.group;
WorkingDirectory = libDir;
};
mkOneshot = command: {
serviceConfig = oneshotServiceConfig;
script = ''
${exportPasswordEnv}
${cfg.package}/bin/pretalx ${command}
'';
};
mkOneshot = command:
recursiveUpdate commonUnitConfig {
serviceConfig = {
Type = "oneshot";
};
script = ''
${exportPasswordEnv}
${pretalxWrapped}/bin/pretalx ${command}
'';
};
in {
${pretalxWebServiceName} = {
${pretalxWebServiceName} = recursiveUpdate commonUnitConfig {
serviceConfig = {
Restart = "on-failure";
EnvironmentFile = environmentFile;
User = cfg.user;
Group = cfg.group;
WorkingDirectory = libDir;
};
environment.PYTHONPATH = PYTHONPATH;
script = ''
${exportPasswordEnv}
exec ${gunicorn}/bin/gunicorn pretalx.wsgi --name=${pretalxWebServiceName} --bind=${gunicornSocket} ${cfg.gunicorn.extraArgs}
'';
wantedBy = ["multi-user.target"];
requires = ["pretalx-init.service" "pretalx-rebuild.service" "pretalx-web.socket"];
requires = ["pretalx-init.service" "pretalx-web.socket"];
after = ["pretalx-init.service"];
};

pretalx-init = {
serviceConfig = oneshotServiceConfig;
pretalx-init = recursiveUpdate commonUnitConfig {
serviceConfig.Type = "oneshot";
script = ''
${exportPasswordEnv}
${pretalxInit}/bin/expect-pretalx-init
Expand All @@ -502,9 +534,19 @@ in {
};

pretalx-migrate = mkOneshot "migrate";
pretalx-rebuild = mkOneshot "rebuild";
pretalx-clearsessions = mkOneshot "clearsessions";
pretalx-runperiodic = mkOneshot "runperiodic";

pretalx-worker = mkIf cfg.celery.enable (recursiveUpdate commonUnitConfig {
description = "pretalx asynchronous job runner";
environment.PYTHONPATH = PYTHONPATH;
after = commonUnitConfig.after ++ ["network.target"];
wantedBy = ["multi-user.target"];
script = ''
${exportPasswordEnv}
${cfg.package.python.pkgs.celery}/bin/celery --app pretalx.celery_app worker ${cfg.celery.extraArgs}
'';
});
};

timers = let
Expand Down
Loading

0 comments on commit 36892fe

Please sign in to comment.