2022-12-19 23:37:05 +00:00
|
|
|
{ self }:
|
|
|
|
{ config, lib, pkgs, ... }: {
|
|
|
|
options.services.buzzrelay = with lib; {
|
|
|
|
enable = mkEnableOption "Enable Fedi.buzz relay";
|
2023-01-11 17:45:45 +00:00
|
|
|
streams = mkOption {
|
2023-01-15 23:04:52 +00:00
|
|
|
type = with types; listOf str;
|
2023-01-11 17:45:45 +00:00
|
|
|
default = [
|
|
|
|
"https://fedi.buzz/api/v1/streaming/public"
|
|
|
|
];
|
|
|
|
};
|
2022-12-19 23:37:05 +00:00
|
|
|
listenPort = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 8000;
|
|
|
|
};
|
|
|
|
hostName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
privKeyFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
pubKeyFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
database = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "buzzrelay";
|
|
|
|
};
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "relay";
|
|
|
|
};
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "relay";
|
|
|
|
};
|
2023-06-23 23:28:12 +00:00
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.enum [ "ERROR" "WARN" "INFO" "DEBUG" "TRACE" ];
|
|
|
|
default = "INFO";
|
|
|
|
};
|
2022-12-19 23:37:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
cfg = config.services.buzzrelay;
|
|
|
|
configFile = builtins.toFile "buzzrelay.toml" (
|
|
|
|
lib.generators.toYAML {} {
|
2023-01-11 17:45:45 +00:00
|
|
|
streams = cfg.streams;
|
2022-12-19 23:37:05 +00:00
|
|
|
hostname = cfg.hostName;
|
|
|
|
listen_port = cfg.listenPort;
|
|
|
|
priv_key_file = cfg.privKeyFile;
|
|
|
|
pub_key_file = cfg.pubKeyFile;
|
2022-12-20 00:09:09 +00:00
|
|
|
db = "host=/var/run/postgresql user=${cfg.user} dbname=${cfg.database}";
|
2022-12-19 23:37:05 +00:00
|
|
|
});
|
2022-12-23 17:21:05 +00:00
|
|
|
inherit (self.packages.${pkgs.system}) buzzrelay;
|
2022-12-19 23:37:05 +00:00
|
|
|
in
|
|
|
|
lib.mkIf cfg.enable {
|
|
|
|
users.users.${cfg.user} = {
|
|
|
|
inherit (cfg) group;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
users.groups.${cfg.group} = {};
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
ensureDatabases = [ cfg.database ];
|
|
|
|
ensureUsers = [ {
|
|
|
|
name = cfg.user;
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE ${cfg.database}" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
} ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.buzzrelay = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2023-01-10 00:10:03 +00:00
|
|
|
after = [ "postgresql.service" "network-online.target" ];
|
2023-06-23 23:28:12 +00:00
|
|
|
environment.RUST_LOG = "buzzrelay=${cfg.logLevel}";
|
2022-12-19 23:37:05 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "notify";
|
2022-12-23 17:21:05 +00:00
|
|
|
WorkingDirectory = "${buzzrelay}/share/buzzrelay";
|
|
|
|
ExecStart = "${buzzrelay}/bin/buzzrelay ${lib.escapeShellArg configFile}";
|
2022-12-19 23:37:05 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
ProtectSystem = "full";
|
|
|
|
Restart = "always";
|
2022-12-20 03:00:28 +00:00
|
|
|
RestartSec = "1s";
|
|
|
|
WatchdogSec = "1800s";
|
2023-05-05 17:32:01 +00:00
|
|
|
LimitNOFile = 40000;
|
2022-12-19 23:37:05 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|