From 467266d6c62391ae155d0583203fa02b06168b05 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 15 Feb 2025 16:55:44 +0100 Subject: [PATCH] ntfy-sh: Add client module Co-authored-by: Sumner Evans Signed-off-by: Matthias Beyer --- modules/programs/ntfy-sh.nix | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 modules/programs/ntfy-sh.nix diff --git a/modules/programs/ntfy-sh.nix b/modules/programs/ntfy-sh.nix new file mode 100644 index 000000000..3dc0c2cf9 --- /dev/null +++ b/modules/programs/ntfy-sh.nix @@ -0,0 +1,59 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.programs.ntfy-sh; + yamlFormat = pkgs.formats.yaml { }; +in with lib; { + options.programs.ntfy-sh = { + enable = mkEnableOption "ntfy-sh"; + enableUserService = mkEnableOption "ntfy-sh user service"; + + package = mkPackageOption pkgs "ntfy-sh" { }; + + configFilePath = mkOption { + type = types.path; + default = "${config.xdg.configHome}/ntfy/client.yml"; + defaultText = literalExpression + "''${config.xdg.configHome}/ntfy/client.yml"; + description = "Path where the configuration file is placed."; + }; + + settings = mkOption { + type = yamlFormat.type; + default = { }; + description = "Configuration for the ntfy binary"; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + home.file.ntfy-sh = { + enable = true; + target = cfg.configFilePath; + + onChange = '' + systemctl --user restart ntfy-sh-client + ''; + + source = mkIf (cfg.settings != { }) + (yamlFormat.generate "ntfy-sh-config" cfg.settings); + }; + + systemd.user.services.ntfy-sh-client = mkIf cfg.enableUserService { + Unit.Description = "ntfy-sh client service"; + + Install.WantedBy = [ "multi-user.target" ]; + + Service = { + Type = "simple"; + Restart = "on-failure"; + ExecStart = '' + ${cfg.package}/bin/ntfy subscribe --config ${cfg.configFilePath} --from-config + ''; + }; + }; + }; + + meta.maintainers = [ maintainers.matthiasbeyer ]; +}