{
  self,
  withIpc ? "unix",
}:
{
  config,
  lib,
  pkgs,
  ...
}:

let
  sb = import ../lib/mkEndpoint.nix;
  isRabbitMqTest = lib.strings.hasPrefix "rabbitmq" withIpc;
in
{
  name = "test-bundle-starts" + lib.optionalString (withIpc != "unix") ("_ipc=" + withIpc);
  skipTypeCheck = true;
  skipLint = true;
  globalTimeout = 120;

  nodes.machine = {
    imports = [ self.nixosModules.default ];

    services.spacebarchat-server =
      let
        cfg = {
          enable = true;
          apiEndpoint = sb.mkEndpoint "api.sb.localhost" 3001 false;
          gatewayEndpoint = sb.mkEndpoint "gw.sb.localhost" 3002 false;
          cdnEndpoint = sb.mkEndpoint "cdn.sb.localhost" 3003 false;
          serverName = "sb.localhost";
          extraEnvironment = {
            DATABASE = "postgres://postgres:postgres@127.0.0.1/spacebar";
            LOG_REQUESTS = "-"; # Log all requests
            LOG_VALIDATION_ERRORS = true;
          };
          ipcMethod = withIpc;

          settings = {
            rabbitmq = {
              host = lib.mkIf isRabbitMqTest "amqp://guest:guest@127.0.0.1:5672";
            };
          };

          nginx.enable = true;
        };
      in
      lib.trace ("Testing with config: " + builtins.toJSON cfg) cfg;
    services.nginx.enable = true;
    services.rabbitmq.enable = isRabbitMqTest;
    services.postgresql = {
      enable = true;
      initdbArgs = [
        "--encoding=UTF8"
        "--locale=C.UTF-8"
        "--data-checksums"
        "--allow-group-access"
      ];
      enableTCPIP = true;
      authentication = pkgs.lib.mkOverride 10 ''
        # TYPE, DATABASE, USER, ADDRESS, METHOD
        local all all trust
        host all all 127.0.0.1/32 trust
        host all all ::1/128 trust
        host all all 0.0.0.0/0 md5
      '';
      initialScript = pkgs.writeText "backend-initScript" ''
        CREATE ROLE spacebar WITH LOGIN PASSWORD 'spacebar' CREATEDB;
        CREATE DATABASE spacebar;
        GRANT ALL PRIVILEGES ON DATABASE spacebar TO spacebar;
      '';
    };
  };

  testScript = ''
    machine.wait_for_unit("spacebar-api")
    machine.wait_for_unit("spacebar-cdn")
    machine.wait_for_unit("spacebar-gateway")
    # Wait for unit doesn't mean the service is actually ready to accept connections
    machine.wait_for_open_port(80)
    machine.wait_for_open_port(3001)
    machine.wait_for_open_port(3002)
    machine.wait_for_open_port(3003)
    # If well known works, its probably fine(tm)?
    machine.succeed("curl -f http://api.sb.localhost/.well-known/spacebar/client")
  '';
}
