From a264fbea00831d8094cefabf690eeded81adbfd6 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sat, 11 Oct 2025 23:04:21 +0900 Subject: [PATCH] newsboat: add timer unit for automatically fetching articles --- modules/programs/newsboat.nix | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/modules/programs/newsboat.nix b/modules/programs/newsboat.nix index 0dfe9a5c1..98558d323 100644 --- a/modules/programs/newsboat.nix +++ b/modules/programs/newsboat.nix @@ -142,6 +142,21 @@ in Extra configuration values that will be appended to the end. ''; }; + + auto-fetch-articles = { + enable = lib.mkEnableOption "automatic article fetcher timer"; + + onCalendar = lib.mkOption { + type = lib.types.str; + default = "daily"; + example = "weekly"; + description = '' + How often to fetch new articles. + + See {manpage}`systemd.time(7)` for more information about the format. + ''; + }; + }; }; }; @@ -154,6 +169,12 @@ in want to manage urls imperatively. ''; } + { + assertion = cfg.auto-fetch-articles.enable -> cfg.package != null; + message = '' + Cannot fetch articles if package is unset. + ''; + } ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; @@ -168,5 +189,39 @@ in "newsboat/urls" = mkIf (cfg.urls != [ ]) { text = urlsFileContents; }; "newsboat/config".text = configFileContents; }; + + systemd.user.services.newsboat-fetch-articles = lib.mkIf cfg.auto-fetch-articles.enable { + Unit = { + Description = "Automatic Newsboat Article Fetcher"; + Documentation = [ "man:newsboat(1)" ]; + }; + + Service = { + Type = "oneshot"; + Slice = "background.slice"; + CPUSchedulingPolicy = "idle"; + IOSchedulingClass = "idle"; + RuntimeDirectory = "newsboat"; + ExecStart = "${lib.getExe pkgs.flock} %t/newsboat.lock ${lib.getExe cfg.package} --execute=reload"; + }; + }; + + systemd.user.timers.newsboat-fetch-articles = lib.mkIf cfg.auto-fetch-articles.enable { + Unit = { + Description = "Automatic Newsboat Article Fetcher"; + Documentation = [ "man:newsboat(1)" ]; + After = [ "network.target" ]; + }; + + Timer = { + Unit = "newsboat-fetch-articles.service"; + OnCalendar = cfg.auto-fetch-articles.onCalendar; + Persistent = true; + }; + + Install = { + WantedBy = [ "timers.target" ]; + }; + }; }; }