2024-10-21 12:31:30 +07:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
2024-09-05 09:42:15 +07:00
|
|
|
let
|
|
|
|
cfg = config.profile.services.ntfy-sh;
|
2024-09-05 13:23:04 +07:00
|
|
|
client = cfg.client;
|
2024-09-05 09:42:15 +07:00
|
|
|
inherit (lib) mkIf;
|
|
|
|
domain = "ntfy.tigor.web.id";
|
2024-09-05 13:23:04 +07:00
|
|
|
listenAddress = "0.0.0.0:15150";
|
2024-10-11 09:45:12 +07:00
|
|
|
configPath = "/etc/ntfy/client.yml";
|
2024-09-05 09:42:15 +07:00
|
|
|
in
|
2024-09-05 13:23:04 +07:00
|
|
|
lib.mkMerge [
|
|
|
|
(mkIf cfg.enable {
|
2024-09-05 09:42:15 +07:00
|
|
|
services.caddy.virtualHosts.${domain}.extraConfig = ''
|
2024-09-05 13:23:04 +07:00
|
|
|
reverse_proxy ${listenAddress}
|
2024-09-05 09:42:15 +07:00
|
|
|
'';
|
2024-09-05 13:23:04 +07:00
|
|
|
|
2024-11-24 20:46:15 +07:00
|
|
|
services.nginx.virtualHosts.${domain} = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations = {
|
|
|
|
"/" = {
|
|
|
|
proxyPass = "http://0.0.0.0:15150";
|
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-05 13:23:04 +07:00
|
|
|
services.ntfy-sh = {
|
|
|
|
enable = true;
|
|
|
|
settings =
|
|
|
|
let
|
|
|
|
base-dir = "/var/lib/ntfy-sh";
|
|
|
|
in
|
|
|
|
rec {
|
|
|
|
listen-http = listenAddress;
|
|
|
|
behind-proxy = true;
|
|
|
|
base-url = "https://${domain}";
|
|
|
|
|
|
|
|
# Performance. Cache and Batching.
|
|
|
|
cache-file = "${base-dir}/cache.db";
|
|
|
|
cache-duration = "24h";
|
|
|
|
cache-batch-size = 10;
|
|
|
|
cache-batch-timeout = "1s";
|
|
|
|
|
|
|
|
# Auth
|
|
|
|
auth-file = "${base-dir}/auth.db";
|
|
|
|
auth-default-access = "deny-all";
|
|
|
|
|
|
|
|
# Attachments
|
|
|
|
attachment-cache-dir = "${base-dir}/attachments";
|
|
|
|
attachment-expiry-duration = cache-duration;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
(mkIf client.enable {
|
2024-09-05 09:42:15 +07:00
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
# Access to `ntfy` cli tool
|
|
|
|
ntfy-sh
|
|
|
|
];
|
|
|
|
|
2024-09-05 11:34:52 +07:00
|
|
|
environment.sessionVariables = {
|
2024-10-11 09:45:12 +07:00
|
|
|
NTFY_CONFIG = configPath;
|
|
|
|
};
|
|
|
|
|
2024-10-21 12:44:35 +07:00
|
|
|
systemd.user.services.ntfy-client = {
|
2024-10-20 17:20:54 +07:00
|
|
|
enable = true;
|
2024-10-22 15:36:58 +07:00
|
|
|
wantedBy = [ "default.target" ];
|
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"dbus.socket"
|
|
|
|
];
|
|
|
|
requires = [ "dbus.socket" ];
|
2024-10-20 17:20:54 +07:00
|
|
|
environment = {
|
|
|
|
DISPLAY = ":0";
|
|
|
|
DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/user/${toString config.profile.user.uid}/bus";
|
|
|
|
};
|
|
|
|
restartTriggers = [ (builtins.toJSON cfg.client.settings) ];
|
2024-10-21 12:31:30 +07:00
|
|
|
path = with pkgs; [
|
|
|
|
bash
|
|
|
|
libnotify
|
|
|
|
];
|
2024-10-20 17:20:54 +07:00
|
|
|
description = "ntfy-sh client";
|
|
|
|
serviceConfig = {
|
2024-10-30 11:42:09 +07:00
|
|
|
ExecStart = lib.meta.getExe (
|
|
|
|
pkgs.writeShellScriptBin "entrypoint.sh" ''
|
|
|
|
until ${pkgs.unixtools.ping}/bin/ping -c 1 ${domain}; do
|
|
|
|
${pkgs.coreutils}/bin/sleep 1;
|
|
|
|
done
|
|
|
|
${pkgs.ntfy-sh}/bin/ntfy --debug subscribe --config /etc/ntfy/client.yml --from-config
|
|
|
|
''
|
|
|
|
);
|
2024-10-20 17:20:54 +07:00
|
|
|
Restart = "on-failure";
|
2024-10-21 12:44:35 +07:00
|
|
|
# User = config.profile.user.uid;
|
|
|
|
# Group = config.profile.user.gid;
|
2024-10-20 17:20:54 +07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-23 19:54:15 +07:00
|
|
|
profile.services.ntfy-sh.client.settings.subscribe = [ { topic = "all"; } ];
|
|
|
|
|
2024-09-05 11:33:50 +07:00
|
|
|
sops = {
|
|
|
|
secrets =
|
|
|
|
let
|
2024-10-21 12:31:30 +07:00
|
|
|
opts = {
|
|
|
|
sopsFile = ../../secrets/ntfy.yaml;
|
|
|
|
};
|
2024-09-05 11:33:50 +07:00
|
|
|
in
|
|
|
|
{
|
2024-10-11 09:45:12 +07:00
|
|
|
"ntfy/tokens/tigor" = opts;
|
2024-09-05 11:33:50 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
templates =
|
2024-10-21 12:31:30 +07:00
|
|
|
let
|
|
|
|
filename = "ntfy-client.yaml";
|
|
|
|
in
|
2024-09-05 11:33:50 +07:00
|
|
|
{
|
|
|
|
${filename} = {
|
2024-10-21 12:31:30 +07:00
|
|
|
content = builtins.readFile (
|
|
|
|
(pkgs.formats.yaml { }).generate filename (
|
|
|
|
{
|
|
|
|
default-host = "https://${domain}";
|
|
|
|
default-token = config.sops.placeholder."ntfy/tokens/tigor";
|
2024-10-24 00:00:15 +07:00
|
|
|
default-command = ''${pkgs.libnotify}/bin/notify-send --app-name="ntfy.sh" --icon="${./ntfy-sh.svg}" --category=im.received --urgency=normal "$title" "$message"'';
|
2024-10-21 12:31:30 +07:00
|
|
|
}
|
|
|
|
// cfg.client.settings
|
|
|
|
)
|
|
|
|
);
|
2024-10-11 09:45:12 +07:00
|
|
|
path = configPath;
|
2024-09-05 11:33:50 +07:00
|
|
|
owner = config.profile.user.name;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-09-05 13:23:04 +07:00
|
|
|
})
|
|
|
|
]
|