This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
nixos-module.nix
165 lines (151 loc) · 4.67 KB
/
nixos-module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
{ config, pkgs, lib, ... }:
let
cfg = config.services.pretix;
# XXX: This will likely contain secrets and will be world-readable
# in the store
configFile = pkgs.writeText "pretix.cfg" (lib.generators.toINI {} cfg.config);
hasLocalPostgres =
cfg.config.database.backend or null == "postgresql" &&
(! (cfg.config.database ? host)
|| builtins.substring 0 1 cfg.config.database.host == "/" # Unix socket
|| cfg.config.database.host == "localhost");
in
{
options.services.pretix = {
enable = lib.mkEnableOption "pretix";
config = lib.mkOption rec {
type = lib.types.attrs;
default = {
pretix = {
instance_name = config.networking.hostName;
url = "${cfg.host}:${toString cfg.port}";
};
redis = {
location = "redis://127.0.0.1/0";
sessions = true;
};
celery = {
backend = "redis://127.0.0.1/1";
broker = "redis://127.0.0.1/2";
};
};
};
host = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
};
port = lib.mkOption {
type = lib.types.port;
default = 8000;
};
secretConfig = lib.mkOption {
type = lib.types.nullOr lib.types.path;
description = ''
Path to a file containing a set of environment variables to override
the configuration file. Use this to store secrets (passwords, etc..)
that shouldn't end-up in the store.
The format is the one described in a note in
<https://docs.pretix.eu/en/latest/admin/config.html>
'';
};
};
config = lib.mkIf cfg.enable {
# virtualisation.oci-containers.backend = lib.mkDefault "podman";
# virtualisation.oci-containers.containers.pretix = {
# volumes = [
# "pretix-data:/data"
# "/var/run/redis:/var/run/redis"
# "${configFile}:/etc/pretix/pretix.cfg"
# ] ++ lib.optional hasLocalPostgres "/run/postgresql:/run/postgresql"
# ;
# image = "pretix/standalone:stable";
# cmd = ["all"];
# extraOptions = ["--network=host"] ++
# lib.optionals (cfg.secretConfig != null) ["--env-file" "${cfg.secretConfig}" ];
# };
users.users.pretix = {
group = "pretix";
isSystemUser = true;
};
users.groups.pretix = {};
systemd.services.pretix-worker = {
serviceConfig = {
WorkingDirectory="/var/lib/pretix";
ExecStart = ''
${pkgs.pretix}/bin/celery -A pretix.celery_app worker -l info
'';
EnvironmentFile="${cfg.secretConfig}";
StateDirectory="pretix";
PrivateTmp = true;
User = "pretix";
Group = "pretix";
};
environment.PRETIX_CONFIG_FILE="${configFile}";
wantedBy = ["multi-user.target"];
};
systemd.services.pretix = {
path = [ pkgs.gettext ];
preStart = ''
${pkgs.pretix}/bin/python -m pretix migrate
'';
serviceConfig = {
WorkingDirectory="/var/lib/pretix";
ExecStart = ''
${pkgs.pretix}/bin/gunicorn \
--pythonpath ${pkgs.pretix}/lib/python3.8/site-packages pretix.wsgi \
--name pretix \
-b ${cfg.host}:${toString cfg.port}
'';
EnvironmentFile="${cfg.secretConfig}";
StateDirectory="pretix";
User = "pretix";
Group = "pretix";
PrivateTmp = true;
Restart = "on-failure";
TimeoutStartSec = 300; # For some reason the first migration is pretty long
};
environment.PRETIX_CONFIG_FILE="${configFile}";
wantedBy = ["multi-user.target"];
};
systemd.services.pretix-periodic = {
serviceConfig = {
WorkingDirectory="/var/lib/pretix";
ExecStart = ''
${pkgs.pretix}/bin/python -m pretix runperiodic
'';
EnvironmentFile="${cfg.secretConfig}";
StateDirectory="pretix";
User = "pretix";
Group = "pretix";
PrivateTmp = true;
};
environment.PRETIX_CONFIG_FILE="${configFile}";
wantedBy = ["multi-user.target"];
startAt = "minutely";
};
services.redis = {
enable = true;
unixSocket = "/var/run/redis/redis.sock";
};
services.postgresql = lib.mkIf hasLocalPostgres {
enable = true;
ensureDatabases = [ "pretix" ];
ensureUsers = [
{
name = "pretix";
ensurePermissions = {
"DATABASE pretix" = "ALL PRIVILEGES";
};
}
];
};
services.rabbitmq.enable = true;
warnings =
(if cfg.config ? mail then [] else [
''
You didn't configure a mail server for pretix.
This is likely to render it unusable.
''
]);
};
}