Skip to content

Commit

Permalink
nixos/wakapi; fix logical errors; add NixOS test (NixOS#350435)
Browse files Browse the repository at this point in the history
  • Loading branch information
fpletz authored Oct 22, 2024
2 parents b963eb2 + 05d349d commit eae7121
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
8 changes: 4 additions & 4 deletions nixos/modules/services/web-apps/wakapi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,21 @@ in
message = "Either `services.wakapi.passwordSalt` or `services.wakapi.passwordSaltFile` must be set.";
}
{
assertion = cfg.passwordSalt != null -> cfg.passwordSaltFile != null;
assertion = !(cfg.passwordSalt != null && cfg.passwordSaltFile != null);
message = "Both `services.wakapi.passwordSalt` `services.wakapi.passwordSaltFile` should not be set at the same time.";
}
{
assertion = cfg.smtpPassword != null -> cfg.smtpPasswordFile != null;
assertion = !(cfg.smtpPassword != null && cfg.smtpPasswordFile != null);
message = "Both `services.wakapi.smtpPassword` `services.wakapi.smtpPasswordFile` should not be set at the same time.";
}
{
assertion = cfg.db.createLocally -> cfg.db.dialect != null;
assertion = cfg.database.createLocally -> cfg.settings.db.dialect != null;
message = "`services.wakapi.database.createLocally` is true, but a database dialect is not set!";
}
];

warnings = [
(lib.optionalString (cfg.db.createLocall -> cfg.db.dialect != "postgres") ''
(lib.optionalString (cfg.database.createLocally -> cfg.settings.db.dialect != "postgres") ''
You have enabled automatic database configuration, but the database dialect is not set to "posgres".
The Wakapi module only supports for PostgreSQL. Please set `services.wakapi.database.createLocally`
Expand Down
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ in {
vscode-remote-ssh = handleTestOn ["x86_64-linux"] ./vscode-remote-ssh.nix {};
vscodium = discoverTests (import ./vscodium.nix);
vsftpd = handleTest ./vsftpd.nix {};
wakapi = handleTest ./wakapi.nix {};
warzone2100 = handleTest ./warzone2100.nix {};
wasabibackend = handleTest ./wasabibackend.nix {};
wastebin = handleTest ./wastebin.nix {};
Expand Down
40 changes: 40 additions & 0 deletions nixos/tests/wakapi.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import ./make-test-python.nix (
{ lib, ... }:
{
name = "Wakapi";

nodes.machine = {
services.wakapi = {
enable = true;
settings = {
server.port = 3000; # upstream default, set explicitly in case upstream changes it

db = {
dialect = "postgres"; # `createLocally` only supports postgres
host = "/run/postgresql";
port = 5432; # service will fail if port is not set
name = "wakapi";
user = "wakapi";
};
};

database.createLocally = true;

# Created with `cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1`
# Prefer passwordSaltFile in production.
passwordSalt = "NpqCY7eY7fMoIWYmPx5mAgr6YoSlXSuI";
};
};

# Test that the service is running and that it is reachable.
# This is not very comprehensive for a test, but it should
# catch very basic mistakes in the module.
testScript = ''
machine.wait_for_unit("wakapi.service")
machine.wait_for_open_port(3000)
machine.succeed("curl --fail http://localhost:3000")
'';

meta.maintainers = [ lib.maintainers.NotAShelf ];
}
)

0 comments on commit eae7121

Please sign in to comment.