blob: 7145bbfa36620cd436cb708b232bff9bc90bedab (
plain) (
blame)
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
|
{
config,
inputs,
lib,
libNginx,
this,
...
}:
let
cfg = config.nixfiles.modules.ntfy;
in
{
options.nixfiles.modules.ntfy = {
enable = lib.mkEnableOption "ntfy";
port = lib.mkOption {
description = "Port.";
type = lib.types.port;
default = 2586;
};
domain = lib.mkOption {
description = "Domain name sans protocol scheme.";
type = lib.types.str;
default = "ntfy.${config.networking.domain}";
};
prometheus = {
enable = lib.mkEnableOption "Prometheus exporter." // {
default = true;
};
address = lib.mkOption {
description = "Address.";
type = lib.types.str;
default = "127.0.0.1";
};
port = lib.mkOption {
description = "Port.";
type = lib.types.port;
default = 9289;
};
};
};
config = lib.mkIf cfg.enable {
ark.files = [ config.services.ntfy-sh.settings.auth-file ];
nixfiles.modules.nginx = {
enable = true;
upstreams.ntfy.servers.${config.services.ntfy-sh.settings.listen-http} = { };
virtualHosts.${cfg.domain} = {
locations = {
"/" = {
proxyPass = "http://ntfy";
proxyWebsockets = true;
};
"/metrics".extraConfig = ''
deny all;
'';
};
extraConfig = libNginx.config.internalOnly;
};
};
services.ntfy-sh = {
enable = true;
settings = {
listen-http = "127.0.0.1:${toString cfg.port}";
base-url = "https://${cfg.domain}";
behind-proxy = true;
enable-metrics = cfg.prometheus.enable;
metrics-listen-http = with cfg.prometheus; lib.optionalString enable "${address}:${toString port}";
};
};
environment.etc."alloy/ntfy.alloy".text = lib.optionalString cfg.prometheus.enable ''
prometheus.scrape "ntfy" {
targets = [
{
__address__ = "127.0.0.1:${toString cfg.prometheus.port}",
instance = "${config.networking.hostName}",
},
]
forward_to = [prometheus.relabel.default.receiver]
}
'';
systemd.services.alloy.reloadTriggers = lib.optionals cfg.prometheus.enable [
config.environment.etc."alloy/ntfy.alloy".source
];
topology.nodes.${this.hostname}.services.ntfy = {
name = "ntfy";
icon = "${inputs.homelab-svg-assets}/assets/ntfy.svg";
info = cfg.domain;
details.listen.text = config.services.ntfy-sh.settings.listen-http;
};
};
}
|