summaryrefslogtreecommitdiff
path: root/nixos/modules/services/pushover.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/modules/services/pushover.nix')
-rw-r--r--nixos/modules/services/pushover.nix92
1 files changed, 92 insertions, 0 deletions
diff --git a/nixos/modules/services/pushover.nix b/nixos/modules/services/pushover.nix
new file mode 100644
index 0000000..d558022
--- /dev/null
+++ b/nixos/modules/services/pushover.nix
@@ -0,0 +1,92 @@
+{ config, lib, pkgs, ... }:
+with lib;
+
+let
+ cfg = config.eth.services.pushover;
+
+ escapeName = name: "pushover-${replaceStrings [ " " "'" ] [ "-" "" ] name}";
+
+ mkService = name: opts: {
+ name = escapeName name;
+ value = {
+ description = "Send ${name} notification";
+ serviceConfig = {
+ DynamicUser = true;
+ ExecStart = pkgs.writeShellScript (escapeName name) ''
+ ${pkgs.curl}/bin/curl \
+ --verbose \
+ --form-string user=${cfg.userKey} \
+ --form-string token=${cfg.apiKey} \
+ --form-string message=${escapeShellArg opts.message} \
+ https://api.pushover.net/1/messages.json
+ '';
+ Environment = [ "HOME=/tmp" ];
+ NoNewPrivileges = true;
+ ProtectHome = true;
+ ProtectKernelTunables = true;
+ ProtectControlGroups = true;
+ ProtectKernelModules = true;
+ RestrictAddressFamilies = "AF_INET AF_INET6";
+ };
+ };
+ };
+
+ mkTimer = name: opts: {
+ name = escapeName name;
+ value = {
+ description = "Periodically send ${name} notification";
+ wants = [ "network.target" ];
+ after = [ "network.target" ];
+ wantedBy = [ "timers.target" ];
+ timerConfig = {
+ Unit = "${escapeName name}.service";
+ OnCalendar = opts.schedule;
+ RandomizedDelaySec = opts.delayUpTo;
+ Persistent = true;
+ };
+ };
+ };
+
+in {
+ options.eth.services.pushover = {
+ enable = mkEnableOption "Send reminders with Pushover";
+
+ userKey = mkOption {
+ type = types.str;
+ description = "Your user key (NB: this will go into the Nix store)";
+ };
+ apiKey = mkOption {
+ type = types.str;
+ description = "The application API key (NB: this will go into the Nix store)";
+ };
+
+ reminders = mkOption {
+ type = types.attrsOf (types.submodule {
+ options = {
+ enable = mkEnableOption "Send a reminder with Pushover";
+
+ message = mkOption {
+ type = types.str;
+ description = "The message to send.";
+ };
+
+ schedule = mkOption {
+ type = types.str;
+ description = "A systemd.time timespec.";
+ };
+ delayUpTo = mkOption {
+ type = types.str;
+ description = "A systemd.time duration.";
+ };
+ };
+ });
+ };
+ };
+
+ config = mkIf cfg.enable {
+ systemd = {
+ services = mapAttrs' mkService cfg.reminders;
+ timers = mapAttrs' mkTimer cfg.reminders;
+ };
+ };
+}