From c3ce64b13a18825ef34d51eca1b5b244e245bd26 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 22 Oct 2024 11:59:09 +0300 Subject: [PATCH 1/4] nixos/wakapi: fix typo in warning conditional This makes the warning work as intended again. --- nixos/modules/services/web-apps/wakapi.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/web-apps/wakapi.nix b/nixos/modules/services/web-apps/wakapi.nix index ab322cad7aed..522c815e3ae3 100644 --- a/nixos/modules/services/web-apps/wakapi.nix +++ b/nixos/modules/services/web-apps/wakapi.nix @@ -196,7 +196,7 @@ in ]; warnings = [ - (lib.optionalString (cfg.db.createLocall -> cfg.db.dialect != "postgres") '' + (lib.optionalString (cfg.db.createLocally -> cfg.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` From fbec0c0d7fa8fcb7864bd598f14014c168cd5693 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 22 Oct 2024 12:05:02 +0300 Subject: [PATCH 2/4] nixos/wakapi: fix failing assertions --- nixos/modules/services/web-apps/wakapi.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/web-apps/wakapi.nix b/nixos/modules/services/web-apps/wakapi.nix index 522c815e3ae3..de6ffaac54cf 100644 --- a/nixos/modules/services/web-apps/wakapi.nix +++ b/nixos/modules/services/web-apps/wakapi.nix @@ -190,13 +190,13 @@ in 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.createLocally -> 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` From a466f1462734692cd484f184a978187f250eabdc Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 22 Oct 2024 12:27:24 +0300 Subject: [PATCH 3/4] nixos/wakapi: fix incorrect assertion conditions Using implication here (->) causes the assertions to fail haphazardly due to the ordering *implied* by the operator. By using AND, we avoid this case. Unsurprisingly, this was caught by the NixOS test. --- nixos/modules/services/web-apps/wakapi.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/web-apps/wakapi.nix b/nixos/modules/services/web-apps/wakapi.nix index de6ffaac54cf..982b572fb2fa 100644 --- a/nixos/modules/services/web-apps/wakapi.nix +++ b/nixos/modules/services/web-apps/wakapi.nix @@ -182,11 +182,11 @@ 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."; } { From 05d349dd293b1f15c14e5e4ceaa75c559670e9da Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 22 Oct 2024 12:28:04 +0300 Subject: [PATCH 4/4] nixos/tests: add wakapi --- nixos/tests/all-tests.nix | 1 + nixos/tests/wakapi.nix | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 nixos/tests/wakapi.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 0934c25ff9d6..fb85df8808f1 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -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 {}; diff --git a/nixos/tests/wakapi.nix b/nixos/tests/wakapi.nix new file mode 100644 index 000000000000..2e611a986e30 --- /dev/null +++ b/nixos/tests/wakapi.nix @@ -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 ]; + } +)