Skip to content
Merged
24 changes: 21 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ let
# set +x
runHook postInstall
'';

passthru.tests = pkgs.testers.runNixOSTest (import ./nix/tests/test-bundle-starts.nix self);
};
in
pkgs.stdenv.mkDerivation {
Expand Down Expand Up @@ -122,5 +120,25 @@ pkgs.stdenv.mkDerivation {
makeWrapper ${pkgs.nodejs_24}/bin/node $out/bin/apply-migrations --prefix NODE_PATH : $out/node_modules --add-flags --enable-source-maps --add-flags $out/dist/apply-migrations.js
'';

passthru.tests = pkgs.testers.runNixOSTest (import ./nix/tests/test-bundle-starts.nix self);
passthru.tests = pkgs.runCommand "spacebar-server-ts-all-tests" rec {
bundleStarts = pkgs.testers.runNixOSTest (import ./nix/tests/test-bundle-starts.nix { inherit self; });
bundleStartsRabbitMqSingle = pkgs.testers.runNixOSTest (
import ./nix/tests/test-bundle-starts.nix {
inherit self;
withIpc = "rabbitmq-single";
}
);
bundleStartsRabbitMqLegacy = pkgs.testers.runNixOSTest (
import ./nix/tests/test-bundle-starts.nix {
inherit self;
withIpc = "rabbitmq-legacy";
}
);

nativeBuildInputs = [
bundleStarts
bundleStartsRabbitMqSingle
bundleStartsRabbitMqLegacy
];
} "touch $out";
}
20 changes: 17 additions & 3 deletions nix/modules/default/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ in
description = "Path to store CDN files.";
};

ipcMethod = lib.mkOption {
type = lib.types.enum [
"unix"
"rabbitmq-single"
"rabbitmq-legacy"
];
default = "unix";
description = ''
How messages should be passed between services.
Note that the C# services (eg. Admin API) currently only supports the "unix" method!
Read more at https://docs.spacebar.chat/setup/server/installation/generic/ipc/.
'';
};

extraEnvironment = lib.mkOption {
default = { };
description = ''
Expand Down Expand Up @@ -98,7 +112,6 @@ in
environment = builtins.mapAttrs (_: val: builtins.toString val) (
{
# things we set by default...
EVENT_TRANSMISSION = "unix";
EVENT_SOCKET_PATH = "/run/spacebar/";
}
// cfg.extraEnvironment
Expand All @@ -108,6 +121,7 @@ in
CONFIG_READONLY = 1;
PORT = toString cfg.apiEndpoint.localPort;
STORAGE_LOCATION = cfg.cdnPath;
EVENT_TRANSMISSION = cfg.ipcMethod;
}
);
serviceConfig = {
Expand All @@ -121,7 +135,6 @@ in
environment = builtins.mapAttrs (_: val: builtins.toString val) (
{
# things we set by default...
EVENT_TRANSMISSION = "unix";
EVENT_SOCKET_PATH = "/run/spacebar/";
}
// cfg.extraEnvironment
Expand All @@ -131,6 +144,7 @@ in
CONFIG_READONLY = 1;
PORT = toString cfg.gatewayEndpoint.localPort;
STORAGE_LOCATION = cfg.cdnPath;
EVENT_TRANSMISSION = cfg.ipcMethod;
APPLY_DB_MIGRATIONS = "false";
}
);
Expand All @@ -144,7 +158,6 @@ in
environment = builtins.mapAttrs (_: val: builtins.toString val) (
{
# things we set by default...
EVENT_TRANSMISSION = "unix";
EVENT_SOCKET_PATH = "/run/spacebar/";
}
// cfg.extraEnvironment
Expand All @@ -154,6 +167,7 @@ in
CONFIG_READONLY = 1;
PORT = toString cfg.cdnEndpoint.localPort;
STORAGE_LOCATION = cfg.cdnPath;
EVENT_TRANSMISSION = cfg.ipcMethod;
APPLY_DB_MIGRATIONS = "false";
}
);
Expand Down
17 changes: 15 additions & 2 deletions nix/tests/test-bundle-starts.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
self:
{
self,
withIpc ? "unix",
}:
{
config,
lib,
Expand All @@ -8,11 +11,13 @@ self:

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

nodes.machine = {
imports = [ self.nixosModules.default ];
Expand All @@ -30,12 +35,20 @@ in
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 = [
Expand Down
Loading
Loading