summaryrefslogtreecommitdiffstats
path: root/nixos/tests/wakapi.nix
blob: 5d30bde150d57600cef4f0cea2b7fd1b5d8aa9bc (plain)
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
{ lib, ... }:
{
  name = "Wakapi";

  nodes = {
    wakapiPsql =
      { pkgs, ... }:
      {
        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";
            };
          };

          # Automatically create our database
          database.createLocally = true; # only works with Postgresql for now

          # Created with `cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1`
          # In production you should use sops-nix, agenix or something alike.
          environmentFiles = [
            (pkgs.writeText "env" ''
              WAKAPI_PASSWORD_SALT=NpqCY7eY7fMoIWYmPx5mAgr6YoSlXSuI
            '')
          ];
        };
      };

    wakapiSqlite =
      { pkgs, ... }:
      {
        services.wakapi = {
          enable = true;
          settings = {
            server.port = 3001;
            db = {
              dialect = "sqlite3";
              name = "wakapi";
              user = "wakapi";
            };
          };

          environmentFiles = [
            (pkgs.writeText "env" ''
              WAKAPI_PASSWORD_SALT=NpqCY7eY7fMoIWYmPx5mAgr6YoSlXSuI
            '')
          ];
        };
      };
  };

  # Test that service works under both postgresql and sqlite3
  # by starting all machines, and curling the default address.
  # This is not very comprehensive for a test, but it should
  # catch very basic mistakes in the module.
  testScript = ''
    with subtest("Test Wakapi with postgresql backend"):
      wakapiPsql.start()
      wakapiPsql.wait_for_unit("wakapi.service")
      wakapiPsql.wait_for_open_port(3000)
      wakapiPsql.succeed("curl --fail http://localhost:3000")

    with subtest("Test Wakapi with sqlite3 backend"):
      wakapiSqlite.start()
      wakapiSqlite.wait_for_unit("wakapi.service")
      wakapiSqlite.wait_for_open_port(3001)
      wakapiSqlite.succeed("curl --fail http://localhost:3001")
  '';

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