-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
nixos-module.nix
117 lines (113 loc) · 3.18 KB
/
nixos-module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{ self }:
{ config, lib, pkgs, ... }: {
options.services.buzzrelay = with lib; {
enable = mkEnableOption "Enable Fedi.buzz relay";
package = mkOption {
type = types.package;
default = self.packages.${pkgs.stdenv.system}.buzzrelay;
};
streams = mkOption {
type = with types; listOf str;
default = [
"https://fedi.buzz/api/v1/streaming/public"
];
};
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 = "buzzrelay";
};
group = mkOption {
type = types.str;
default = "buzzrelay";
};
logLevel = mkOption {
type = types.enum [ "ERROR" "WARN" "INFO" "DEBUG" "TRACE" ];
default = "INFO";
};
redis = {
connection = mkOption {
type = with types; nullOr str;
default = null;
};
passwordFile = mkOption {
type = with types; nullOr path;
default = null;
};
inTopic = mkOption {
type = types.str;
default = "relay-in";
};
};
};
config =
let
cfg = config.services.buzzrelay;
configFile = builtins.toFile "buzzrelay.yaml" (
lib.generators.toYAML {} {
streams = cfg.streams;
hostname = cfg.hostName;
listen_port = cfg.listenPort;
priv_key_file = cfg.privKeyFile;
pub_key_file = cfg.pubKeyFile;
db = "host=/var/run/postgresql user=${cfg.user} dbname=${cfg.database}";
redis = if cfg.redis.connection != null
then {
connection = cfg.redis.connection;
password_file = cfg.redis.passwordFile;
in_topic = cfg.redis.inTopic;
}
else null;
});
buzzrelay = cfg.package;
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;
ensureDBOwnership = true;
} ];
};
systemd.services.buzzrelay = {
wantedBy = [ "multi-user.target" ];
after = [ "postgresql.service" "network-online.target" ];
wants = [ "network-online.target" ];
environment.RUST_LOG = "buzzrelay=${cfg.logLevel}";
serviceConfig = {
Type = "notify";
WorkingDirectory = "${buzzrelay}/share/buzzrelay";
ExecStart = "${lib.getExe buzzrelay} ${lib.escapeShellArg configFile}";
User = cfg.user;
Group = cfg.group;
ProtectSystem = "full";
Restart = "always";
RestartSec = "1s";
WatchdogSec = "1800s";
LimitNOFile = 40000;
};
};
};
}