Skip to content

Commit eae7121

Browse files
authored
nixos/wakapi; fix logical errors; add NixOS test (#350435)
2 parents b963eb2 + 05d349d commit eae7121

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

nixos/modules/services/web-apps/wakapi.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,21 @@ in
182182
message = "Either `services.wakapi.passwordSalt` or `services.wakapi.passwordSaltFile` must be set.";
183183
}
184184
{
185-
assertion = cfg.passwordSalt != null -> cfg.passwordSaltFile != null;
185+
assertion = !(cfg.passwordSalt != null && cfg.passwordSaltFile != null);
186186
message = "Both `services.wakapi.passwordSalt` `services.wakapi.passwordSaltFile` should not be set at the same time.";
187187
}
188188
{
189-
assertion = cfg.smtpPassword != null -> cfg.smtpPasswordFile != null;
189+
assertion = !(cfg.smtpPassword != null && cfg.smtpPasswordFile != null);
190190
message = "Both `services.wakapi.smtpPassword` `services.wakapi.smtpPasswordFile` should not be set at the same time.";
191191
}
192192
{
193-
assertion = cfg.db.createLocally -> cfg.db.dialect != null;
193+
assertion = cfg.database.createLocally -> cfg.settings.db.dialect != null;
194194
message = "`services.wakapi.database.createLocally` is true, but a database dialect is not set!";
195195
}
196196
];
197197

198198
warnings = [
199-
(lib.optionalString (cfg.db.createLocall -> cfg.db.dialect != "postgres") ''
199+
(lib.optionalString (cfg.database.createLocally -> cfg.settings.db.dialect != "postgres") ''
200200
You have enabled automatic database configuration, but the database dialect is not set to "posgres".
201201
202202
The Wakapi module only supports for PostgreSQL. Please set `services.wakapi.database.createLocally`

nixos/tests/all-tests.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ in {
11081108
vscode-remote-ssh = handleTestOn ["x86_64-linux"] ./vscode-remote-ssh.nix {};
11091109
vscodium = discoverTests (import ./vscodium.nix);
11101110
vsftpd = handleTest ./vsftpd.nix {};
1111+
wakapi = handleTest ./wakapi.nix {};
11111112
warzone2100 = handleTest ./warzone2100.nix {};
11121113
wasabibackend = handleTest ./wasabibackend.nix {};
11131114
wastebin = handleTest ./wastebin.nix {};

nixos/tests/wakapi.nix

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import ./make-test-python.nix (
2+
{ lib, ... }:
3+
{
4+
name = "Wakapi";
5+
6+
nodes.machine = {
7+
services.wakapi = {
8+
enable = true;
9+
settings = {
10+
server.port = 3000; # upstream default, set explicitly in case upstream changes it
11+
12+
db = {
13+
dialect = "postgres"; # `createLocally` only supports postgres
14+
host = "/run/postgresql";
15+
port = 5432; # service will fail if port is not set
16+
name = "wakapi";
17+
user = "wakapi";
18+
};
19+
};
20+
21+
database.createLocally = true;
22+
23+
# Created with `cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1`
24+
# Prefer passwordSaltFile in production.
25+
passwordSalt = "NpqCY7eY7fMoIWYmPx5mAgr6YoSlXSuI";
26+
};
27+
};
28+
29+
# Test that the service is running and that it is reachable.
30+
# This is not very comprehensive for a test, but it should
31+
# catch very basic mistakes in the module.
32+
testScript = ''
33+
machine.wait_for_unit("wakapi.service")
34+
machine.wait_for_open_port(3000)
35+
machine.succeed("curl --fail http://localhost:3000")
36+
'';
37+
38+
meta.maintainers = [ lib.maintainers.NotAShelf ];
39+
}
40+
)

0 commit comments

Comments
 (0)