Unverified Commit 459db35f authored by Wolfgang Walther's avatar Wolfgang Walther Committed by GitHub
Browse files

nixos/wakapi: fix running under sqlite3; add stateDir; add sqlite test case (#370497)

parents 167585a6 fde8246e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -26,6 +26,14 @@ in
  options.services.wakapi = {
    enable = mkEnableOption "Wakapi";
    package = mkPackageOption pkgs "wakapi" { };
    stateDir = mkOption {
      type = types.path;
      default = "/var/lib/wakapi";
      description = ''
        The state directory where data is stored. Will also be used as the
        working directory for the wakapi service.
      '';
    };

    settings = mkOption {
      inherit (settingsFormat) type;
@@ -166,6 +174,8 @@ in
        RestrictNamespaces = true;
        RestrictRealtime = true;
        RestrictSUIDSGID = true;
        WorkingDirectory = cfg.stateDir;
        RuntimeDirectory = "wakapi";
        StateDirectory = "wakapi";
        StateDirectoryMode = "0700";
        Restart = "always";
+47 −20
Original line number Diff line number Diff line
@@ -3,12 +3,12 @@ import ./make-test-python.nix (
  {
    name = "Wakapi";

    nodes.machine = {
    nodes = {
      wakapiPsql = {
        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";
@@ -18,7 +18,8 @@ import ./make-test-python.nix (
            };
          };

        database.createLocally = true;
          # 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`
          # Prefer passwordSaltFile in production.
@@ -26,13 +27,39 @@ import ./make-test-python.nix (
        };
      };

    # Test that the service is running and that it is reachable.
      wakapiSqlite = {
        services.wakapi = {
          enable = true;
          settings = {
            server.port = 3001;
            db = {
              dialect = "sqlite3";
              name = "wakapi";
              user = "wakapi";
            };
          };

          passwordSalt = "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 = ''
      machine.wait_for_unit("wakapi.service")
      machine.wait_for_open_port(3000)
      machine.succeed("curl --fail http://localhost:3000")
      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 ];