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