ntfy: update client config to auto subscribe

This commit is contained in:
Tigor Hutasuhut 2024-10-11 09:45:12 +07:00
parent 9a6e73d751
commit ef34dbb44f
3 changed files with 52 additions and 17 deletions

View file

@ -1,4 +1,4 @@
{ config, lib, ... }: { config, lib, pkgs, ... }:
let let
inherit (lib) mkEnableOption mkOption types; inherit (lib) mkEnableOption mkOption types;
in in
@ -24,10 +24,16 @@ in
navidrome.enable = mkEnableOption "navidrome"; navidrome.enable = mkEnableOption "navidrome";
ntfy-sh.enable = mkEnableOption "ntfy-sh"; ntfy-sh.enable = mkEnableOption "ntfy-sh";
ntfy-sh.client.enable = mkOption { ntfy-sh.client = {
settings = lib.mkOption {
type = (pkgs.formats.yaml { }).type;
default = { };
};
enable = mkOption {
type = types.bool; type = types.bool;
default = config.profile.services.ntfy-sh.enable; default = config.profile.services.ntfy-sh.enable;
}; };
};
couchdb.enable = mkEnableOption "couchdb"; couchdb.enable = mkEnableOption "couchdb";

View file

@ -59,8 +59,8 @@ let
} }
]); ]);
in in
{ lib.mkMerge [
config = mkIf (podman.enable && podman.${name}.enable) { (mkIf podman.${name}.enable {
sops = { sops = {
secrets = secrets =
let let
@ -142,6 +142,7 @@ in
mode = "0444"; mode = "0444";
}; };
virtualisation.oci-containers.containers.${name} = { virtualisation.oci-containers.containers.${name} = {
inherit image; inherit image;
hostname = name; hostname = name;
@ -163,5 +164,13 @@ in
"io.containers.autoupdate" = "registry"; "io.containers.autoupdate" = "registry";
}; };
}; };
}; })
{
profile.services.ntfy-sh.client.settings.subscribe = [
{
topic = "ytptube";
command = ''${pkgs.libnotify}/bin/notify-send --category=im.received --urgency=normal "$title" "$message"'';
} }
];
}
]

View file

@ -5,6 +5,7 @@ let
inherit (lib) mkIf; inherit (lib) mkIf;
domain = "ntfy.tigor.web.id"; domain = "ntfy.tigor.web.id";
listenAddress = "0.0.0.0:15150"; listenAddress = "0.0.0.0:15150";
configPath = "/etc/ntfy/client.yml";
in in
lib.mkMerge [ lib.mkMerge [
(mkIf cfg.enable { (mkIf cfg.enable {
@ -46,7 +47,26 @@ lib.mkMerge [
]; ];
environment.sessionVariables = { environment.sessionVariables = {
NTFY_CONFIG = "/etc/ntfy/client.yml"; NTFY_CONFIG = configPath;
};
systemd.services.ntfy-client = {
enable = true;
wantedBy = [ "multi-user.target" ];
description = "ntfy client";
after = [ "network-online.target" ];
restartTriggers = [ (builtins.toJSON cfg.client.settings) ];
environment = {
DISPLAY = ":0";
DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/user/${toString config.profile.user.uid}/bus";
};
path = [ pkgs.bash ];
serviceConfig = {
User = toString config.profile.user.uid;
Group = toString config.profile.user.gid;
ExecStart = "${pkgs.ntfy-sh}/bin/ntfy subscribe --config ${configPath} --from-config";
Restart = "on-failure";
};
}; };
sops = { sops = {
@ -55,20 +75,20 @@ lib.mkMerge [
opts = { sopsFile = ../../secrets/ntfy.yaml; }; opts = { sopsFile = ../../secrets/ntfy.yaml; };
in in
{ {
"ntfy/default/user" = opts; "ntfy/tokens/tigor" = opts;
"ntfy/default/password" = opts;
}; };
templates = templates =
let filename = "ntfy-client.yaml"; in let filename = "ntfy-client.yaml"; in
{ {
${filename} = { ${filename} = {
content = builtins.readFile ((pkgs.formats.yaml { }).generate filename { content = builtins.readFile ((pkgs.formats.yaml { }).generate filename (
{
default-host = "https://${domain}"; default-host = "https://${domain}";
default-user = config.sops.placeholder."ntfy/default/user"; detault-token = config.sops.placeholder."ntfy/tokens/tigor";
default-password = config.sops.placeholder."ntfy/default/password"; } // cfg.client.settings
}); ));
path = "/etc/ntfy/client.yml"; path = configPath;
owner = config.profile.user.name; owner = config.profile.user.name;
}; };
}; };