From be9295b6aab3a0b4706eb6d0c84182dde40b5c0e Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 22 Jul 2023 09:58:45 +0800 Subject: [PATCH] services/matcha: init module --- modules/home-manager/default.nix | 1 + modules/home-manager/services/matcha.nix | 85 ++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 modules/home-manager/services/matcha.nix diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix index 874a3b41..c1472eb7 100644 --- a/modules/home-manager/default.nix +++ b/modules/home-manager/default.nix @@ -12,6 +12,7 @@ let ./services/bleachbit.nix ./services/distant.nix ./services/gallery-dl.nix + ./services/matcha.nix ./services/plover.nix ./services/yt-dlp.nix ]; diff --git a/modules/home-manager/services/matcha.nix b/modules/home-manager/services/matcha.nix new file mode 100644 index 00000000..168df4d0 --- /dev/null +++ b/modules/home-manager/services/matcha.nix @@ -0,0 +1,85 @@ +{ config, options, lib, pkgs, ... }: + +let + cfg = config.services.matcha; + + settingsFormat = pkgs.formats.yaml { }; + settingsFile = settingsFormat.generate "matcha-config" cfg.settings; +in +{ + options.services.matcha = { + enable = lib.mkEnableOption "Matcha periodic feed digest generator"; + + package = lib.mkOption { + description = '' + The package containing the {command}`matcha` executable. + ''; + type = lib.types.package; + default = pkgs.matcha; + defaultText = "pkgs.matcha"; + }; + + settings = lib.mkOption { + description = '' + The configuration to be used with the Matcha service. + ''; + type = settingsFormat.type; + default = { }; + defaultText = "{}"; + example = lib.literalExpression '' + { + markdown_dir_path = "''${config.xdg.userDirs.documents}/Matcha"; + feeds = [ + "http://hnrss.org/best 10" + "https://waitbutwhy.com/feed" + "http://tonsky.me/blog/atom.xml" + "http://www.joelonsoftware.com/rss.xml" + "https://www.youtube.com/feeds/videos.xml?channel_id=UCHnyfMqiRRG1u-2MsSQLbXA" + ]; + opml_file_path = "''${config.xdg.userDirs.documents}/feeds.opml"; + } + ''; + }; + + startAt = lib.mkOption { + description = '' + How often the service generates the digest. + + The value is used to `Calendar.OnCalendar` systemd timer option. For + more details about the value format, see {manpage}`systemd.time(7)`. + ''; + type = lib.types.str; + default = "daily"; + example = "weekly"; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.user.services.matcha = { + Unit = { + Description = "Matcha periodic feed digest generator"; + Documentation = [ "https://github.com/piqoni/matcha" ]; + }; + + Install.WantedBy = [ "default.target" ]; + + Service = { + ExecStart = "${cfg.package}/bin/matcha -c ${settingsFile}"; + Restart = "on-failure"; + }; + }; + + systemd.user.timers.matcha = { + Unit = { + Description = "Matcha periodic feed digest generator"; + Documentation = [ "https://github.com/piqoni/matcha" ]; + After = [ "network.target" ]; + }; + Install.WantedBy = [ "timers.target" ]; + Timer = { + Persistent = true; + OnCalendar = cfg.startAt; + }; + }; + }; +}