allow creating multiple conduwuit instances
This commit is contained in:
parent
8e618b0d68
commit
819c467414
1 changed files with 83 additions and 71 deletions
|
@ -3,11 +3,8 @@ let
|
||||||
cfg = config.recipes.conduwuit;
|
cfg = config.recipes.conduwuit;
|
||||||
|
|
||||||
format = pkgs.formats.toml { };
|
format = pkgs.formats.toml { };
|
||||||
configFile = format.generate "conduwuit.toml" cfg.settings;
|
conduitSubmodule = { name, ... }: {
|
||||||
in
|
options = {
|
||||||
{
|
|
||||||
meta.maintainers = with lib.maintainers; [ adtya ];
|
|
||||||
options.recipes.conduwuit = {
|
|
||||||
enable = lib.mkEnableOption "conduwuit";
|
enable = lib.mkEnableOption "conduwuit";
|
||||||
|
|
||||||
extraEnvironment = lib.mkOption {
|
extraEnvironment = lib.mkOption {
|
||||||
|
@ -77,19 +74,21 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
systemdService = name: serviceDefinition:
|
||||||
systemd.services.conduwuit = {
|
let configFile = format.generate "conduwuit-${name}.toml" serviceDefinition.settings; in {
|
||||||
description = "Conduwuit Matrix Server";
|
enable = serviceDefinition.enable;
|
||||||
|
description = "Conduwuit Matrix Server (${name})";
|
||||||
documentation = [ "https://conduwuit.puppyirl.gay" ];
|
documentation = [ "https://conduwuit.puppyirl.gay" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" ];
|
||||||
environment = cfg.extraEnvironment;
|
environment = serviceDefinition.extraEnvironment;
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "notify";
|
Type = "notify";
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
EnvironmentFile = cfg.environmentFiles;
|
EnvironmentFile = serviceDefinition.environmentFiles;
|
||||||
AmbientCapabilities = [ ];
|
AmbientCapabilities = [ ];
|
||||||
CapabilityBoundingSet = [ ];
|
CapabilityBoundingSet = [ ];
|
||||||
DevicePolicy = "closed";
|
DevicePolicy = "closed";
|
||||||
|
@ -134,8 +133,8 @@ in
|
||||||
"~@ipc"
|
"~@ipc"
|
||||||
];
|
];
|
||||||
SystemCallErrorNumber = "EPERM";
|
SystemCallErrorNumber = "EPERM";
|
||||||
StateDirectory = "conduwuit";
|
StateDirectory = "conduwuit-${name}";
|
||||||
RuntimeDirectory = "conduwuit";
|
RuntimeDirectory = "conduwuit-${name}";
|
||||||
RuntimeDirectoryMode = "0750";
|
RuntimeDirectoryMode = "0750";
|
||||||
ExecStart = "${cfg.package}/bin/conduit --config ${configFile}";
|
ExecStart = "${cfg.package}/bin/conduit --config ${configFile}";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
|
@ -143,5 +142,18 @@ in
|
||||||
StartLimitBurst = 5;
|
StartLimitBurst = 5;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
mkSystemdService = (name: serviceDefinition: lib.nameValuePair "conduit-${name}" (systemdService name serviceDefinition));
|
||||||
|
in
|
||||||
|
{
|
||||||
|
meta.maintainers = with lib.maintainers; [ adtya ];
|
||||||
|
options.recipes.conduwuit.instances = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf (lib.types.submodule conduitSubmodule);
|
||||||
|
default = { };
|
||||||
|
defaultText = lib.literalExpression { };
|
||||||
|
description = "Configuration for a conduit instance";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf (cfg.instances != { }) {
|
||||||
|
systemd.services = lib.mappAttrs' mkSystemdService cfg.instances;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue