|
48 | 48 | COMPRESS_OFFLINE = True |
49 | 49 | DEBUG = False |
50 | 50 |
|
51 | | - DATABASES = { |
52 | | - "default": { |
53 | | - "ENGINE": "django.db.backends.postgresql", |
54 | | - "HOST": "/run/postgresql", |
55 | | - "NAME": "weblate", |
56 | | - "USER": "weblate", |
57 | | - } |
58 | | - } |
59 | | -
|
60 | 51 | with open("${cfg.djangoSecretKeyFile}") as f: |
61 | 52 | SECRET_KEY = f.read().rstrip("\n") |
62 | 53 |
|
|
65 | 56 | "BACKEND": "django_redis.cache.RedisCache", |
66 | 57 | "LOCATION": "unix://${config.services.redis.servers.weblate.unixSocket}", |
67 | 58 | "OPTIONS": { |
68 | | - "CLIENT_CLASS": "django_redis.client.DefaultClient", |
69 | | - "PASSWORD": None, |
70 | | - "CONNECTION_POOL_KWARGS": {}, |
| 59 | + "CLIENT_CLASS": "django_redis.client.DefaultClient", |
| 60 | + "PASSWORD": None, |
| 61 | + "CONNECTION_POOL_KWARGS": {}, |
71 | 62 | }, |
72 | 63 | "KEY_PREFIX": "weblate", |
73 | 64 | "TIMEOUT": 3600, |
|
80 | 71 | } |
81 | 72 | } |
82 | 73 |
|
83 | | -
|
84 | 74 | CELERY_TASK_ALWAYS_EAGER = False |
85 | 75 | CELERY_BROKER_URL = "redis+socket://${config.services.redis.servers.weblate.unixSocket}" |
86 | 76 | CELERY_RESULT_BACKEND = CELERY_BROKER_URL |
|
93 | 83 | OTP_WEBAUTHN_RP_NAME = SITE_TITLE |
94 | 84 | OTP_WEBAUTHN_RP_ID = SITE_DOMAIN.split(":")[0] |
95 | 85 | OTP_WEBAUTHN_ALLOWED_ORIGINS = [SITE_URL] |
96 | | -
|
| 86 | + '' |
| 87 | + + lib.optionalString cfg.configurePostgresql '' |
| 88 | + DATABASES = { |
| 89 | + "default": { |
| 90 | + "ENGINE": "django.db.backends.postgresql", |
| 91 | + "HOST": "/run/postgresql", |
| 92 | + "NAME": "weblate", |
| 93 | + "USER": "weblate", |
| 94 | + } |
| 95 | + } |
97 | 96 | '' |
98 | 97 | + lib.optionalString cfg.smtp.enable '' |
99 | | - ADMINS = (("Weblate Admin", "${cfg.smtp.user}"),) |
100 | | -
|
101 | 98 | EMAIL_HOST = "${cfg.smtp.host}" |
102 | 99 | EMAIL_USE_TLS = True |
| 100 | + EMAIL_PORT = ${builtins.toString cfg.smtp.port} |
| 101 | + SERVER_EMAIL = "${cfg.smtp.from}" |
| 102 | + DEFAULT_FROM_EMAIL = "${cfg.smtp.from}" |
| 103 | + '' |
| 104 | + + lib.optionalString (cfg.smtp.enable && cfg.smtp.user != null) '' |
| 105 | + ADMINS = (("Weblate Admin", "${cfg.smtp.user}"),) |
103 | 106 | EMAIL_HOST_USER = "${cfg.smtp.user}" |
104 | | - SERVER_EMAIL = "${cfg.smtp.user}" |
105 | | - DEFAULT_FROM_EMAIL = "${cfg.smtp.user}" |
106 | | - EMAIL_PORT = 587 |
| 107 | + '' |
| 108 | + + lib.optionalString (cfg.smtp.enable && cfg.smtp.passwordFile != null) '' |
107 | 109 | with open("${cfg.smtp.passwordFile}") as f: |
108 | 110 | EMAIL_HOST_PASSWORD = f.read().rstrip("\n") |
109 | | -
|
110 | 111 | '' |
111 | 112 | + cfg.extraConfig; |
112 | 113 | settings_py = |
|
139 | 140 | tesseract |
140 | 141 | licensee |
141 | 142 | mercurial |
| 143 | + openssh |
142 | 144 | ]; |
143 | 145 | in |
144 | 146 | { |
|
166 | 168 | type = lib.types.path; |
167 | 169 | }; |
168 | 170 |
|
| 171 | + configurePostgresql = lib.mkOption { |
| 172 | + type = lib.types.bool; |
| 173 | + default = true; |
| 174 | + description = '' |
| 175 | + Whether to enable and configure a local PostgreSQL server by creating a user and database for weblate. |
| 176 | + The default `settings` reference this database, if you disable this option you must provide a database URL in `extraConfig`. |
| 177 | + ''; |
| 178 | + }; |
| 179 | + |
169 | 180 | extraConfig = lib.mkOption { |
170 | 181 | type = lib.types.lines; |
171 | 182 | default = ""; |
|
176 | 187 |
|
177 | 188 | smtp = { |
178 | 189 | enable = lib.mkEnableOption "Weblate SMTP support"; |
| 190 | + |
| 191 | + from = lib.mkOption { |
| 192 | + description = "The from address being used in sent emails."; |
| 193 | + |
| 194 | + default = config.services.weblate.smtp.user; |
| 195 | + defaultText = "config.services.weblate.smtp.user"; |
| 196 | + type = lib.types.str; |
| 197 | + }; |
| 198 | + |
179 | 199 | user = lib.mkOption { |
180 | 200 | description = "SMTP login name."; |
181 | 201 | |
182 | | - type = lib.types.str; |
| 202 | + type = lib.types.nullOr lib.types.str; |
| 203 | + default = null; |
183 | 204 | }; |
184 | 205 |
|
185 | 206 | host = lib.mkOption { |
|
188 | 209 | example = "127.0.0.1"; |
189 | 210 | }; |
190 | 211 |
|
| 212 | + port = lib.mkOption { |
| 213 | + description = "SMTP port used when sending emails to users."; |
| 214 | + type = lib.types.port; |
| 215 | + default = 587; |
| 216 | + example = 25; |
| 217 | + }; |
| 218 | + |
191 | 219 | passwordFile = lib.mkOption { |
192 | 220 | description = '' |
193 | 221 | Location of a file containing the SMTP password. |
194 | 222 |
|
195 | 223 | This should be a path pointing to a file with secure permissions (not /nix/store). |
196 | 224 | ''; |
197 | | - type = lib.types.path; |
| 225 | + type = lib.types.nullOr lib.types.path; |
| 226 | + default = null; |
198 | 227 | }; |
199 | 228 | }; |
200 | | - |
201 | 229 | }; |
202 | 230 | }; |
203 | 231 |
|
|
218 | 246 | "/media/".alias = "/var/lib/weblate/media/"; |
219 | 247 | "/".proxyPass = "http://unix:///run/weblate.socket"; |
220 | 248 | }; |
221 | | - |
222 | 249 | }; |
223 | 250 | }; |
224 | 251 |
|
|
237 | 264 |
|
238 | 265 | systemd.services.weblate-migrate = { |
239 | 266 | description = "Weblate migration"; |
240 | | - after = [ "weblate-postgresql-setup.service" ]; |
241 | | - requires = [ "weblate-postgresql-setup.service" ]; |
| 267 | + after = [ |
| 268 | + "weblate-postgresql-setup.service" |
| 269 | + "redis-weblate.service" |
| 270 | + ]; |
| 271 | + requires = [ |
| 272 | + "weblate-postgresql-setup.service" |
| 273 | + "redis-weblate.service" |
| 274 | + ]; |
242 | 275 | # We want this to be active on boot, not just on socket activation |
243 | 276 | wantedBy = [ "multi-user.target" ]; |
244 | 277 | inherit environment; |
|
256 | 289 | description = "Weblate Celery"; |
257 | 290 | after = [ |
258 | 291 | "network.target" |
259 | | - "redis.service" |
| 292 | + "redis-weblate.service" |
260 | 293 | "postgresql.service" |
261 | 294 | ]; |
262 | 295 | # We want this to be active on boot, not just on socket activation |
|
371 | 404 | unixSocketPerm = 770; |
372 | 405 | }; |
373 | 406 |
|
374 | | - services.postgresql = { |
| 407 | + services.postgresql = lib.mkIf cfg.configurePostgresql { |
375 | 408 | enable = true; |
376 | 409 | ensureUsers = [ |
377 | 410 | { |
|
0 commit comments