NixOS: systemd slices

This commit is contained in:
Rory&
2026-07-21 14:20:00 +02:00
parent 6494a14e8a
commit d64455b729
7 changed files with 52 additions and 28 deletions
+1
View File
@@ -59,6 +59,7 @@ in
);
serviceConfig = {
ExecStart = "${self.packages.${pkgs.stdenv.hostPlatform.system}.Spacebar-AdminApi}/bin/Spacebar.AdminApi";
Slice = "system-spacebar.slice";
};
};
};
+1
View File
@@ -54,6 +54,7 @@ in
);
serviceConfig = {
ExecStart = "${self.packages.${pkgs.stdenv.hostPlatform.system}.Spacebar-AdminApi}/bin/Spacebar.AdminApi";
Slice = "system-spacebar.slice";
};
};
};
+1
View File
@@ -84,6 +84,7 @@ in
);
serviceConfig = {
ExecStart = "${lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.Spacebar-Offload}";
Slice = "system-spacebar.slice";
};
};
};
+1
View File
@@ -60,6 +60,7 @@ in
);
serviceConfig = {
ExecStart = "${self.packages.${pkgs.stdenv.hostPlatform.system}.Spacebar-UApi}/bin/Spacebar.UApi";
Slice = "system-spacebar.slice";
};
};
};
+8
View File
@@ -106,6 +106,11 @@ in
// secrets.options;
config = lib.mkIf cfg.enable {
systemd.slices.system-spacebar = {
description = "Spacebar server";
documentation = [ "https://docs.spacebar.chat"];
};
services.spacebarchat-server.uApi.extraConfiguration.Spacebar.UApi.FallbackApiEndpoint = "http://127.0.0.1:${toString cfg.apiEndpoint.localPort}";
systemd.services.spacebar-api = makeServerTsService {
@@ -128,6 +133,7 @@ in
serviceConfig = {
ExecStart = "${cfg.package}/bin/start-api";
Type = "notify";
Slice = "system-spacebar.slice";
};
};
@@ -153,6 +159,7 @@ in
serviceConfig = {
ExecStart = "${cfg.package}/bin/start-gateway";
Type = "notify";
Slice = "system-spacebar.slice";
};
};
@@ -177,6 +184,7 @@ in
serviceConfig = {
ExecStart = "${cfg.package}/bin/start-cdn";
Type = "notify";
Slice = "system-spacebar.slice";
};
});
};
+38 -28
View File
@@ -21,34 +21,44 @@ in
};
};
config = lib.mkIf cfg.enable {
systemd.services = builtins.listToAttrs (
map (port: {
name = "spacebar-gateway-${toString port}";
value = makeServerTsService {
description = "Spacebar Server - Gateway (extra port ${toString port})";
# after = [ "spacebar-api.service" ];
environment = builtins.mapAttrs (_: val: builtins.toString val) (
{
# things we set by default...
EVENT_TRANSMISSION = "unix";
EVENT_SOCKET_PATH = "/run/spacebar/";
}
// cfg.extraEnvironment
// {
# things we force...
CONFIG_PATH = configFile;
CONFIG_READONLY = 1;
PORT = toString port;
STORAGE_LOCATION = cfg.cdnPath;
APPLY_DB_MIGRATIONS = "false";
}
);
serviceConfig = {
ExecStart = "${cfg.package}/bin/start-gateway";
config = lib.mkIf (builtins.any (_: true) cfg.extraGatewayPorts) {
systemd.slices.system-spacebar-gateway = {
description = "Spacebar server (gateway shards)";
documentation = [ "https://docs.spacebar.chat" ];
};
systemd.services =
builtins.listToAttrs (
map (port: {
name = "spacebar-gateway-${toString port}";
value = makeServerTsService {
description = "Spacebar Server - Gateway (extra port ${toString port})";
# after = [ "spacebar-api.service" ];
environment = builtins.mapAttrs (_: val: builtins.toString val) (
{
# things we set by default...
EVENT_TRANSMISSION = "unix";
EVENT_SOCKET_PATH = "/run/spacebar/";
}
// cfg.extraEnvironment
// {
# things we force...
CONFIG_PATH = configFile;
CONFIG_READONLY = 1;
PORT = toString port;
STORAGE_LOCATION = cfg.cdnPath;
APPLY_DB_MIGRATIONS = "false";
}
);
serviceConfig = {
ExecStart = "${cfg.package}/bin/start-gateway";
Slice = "system-spacebar-gateway.slice";
};
};
};
}) cfg.extraGatewayPorts
);
}) cfg.extraGatewayPorts
)
// {
"spacebar-gateway".serviceConfig.Slice = "system-spacebar-gateway.slice";
};
};
}
+2
View File
@@ -70,6 +70,7 @@ in
serviceConfig = {
ExecStart = "${cfg.package}/bin/start-webrtc";
Type = "notify";
Slice = "system-spacebar.slice";
};
};
@@ -77,6 +78,7 @@ in
description = "Spacebar Server - Pion SFU";
serviceConfig = {
ExecStart = "${lib.getExe cfg.pion-sfu.package} -ip ${cfg.pion-sfu.publicIp} -port ${toString cfg.pion-sfu.listenPort}";
Slice = "system-spacebar.slice";
};
};
};