2018-06-08 21:09:20 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.newsboat;
|
2020-02-02 00:39:17 +01:00
|
|
|
wrapQuote = x: ''"${x}"'';
|
2018-06-08 21:09:20 +02:00
|
|
|
|
2021-04-09 22:00:52 +02:00
|
|
|
urlsFileContents = let
|
|
|
|
mkUrlEntry = u:
|
|
|
|
concatStringsSep " " ([ u.url ] ++ map wrapQuote u.tags
|
|
|
|
++ optional (u.title != null) (wrapQuote "~${u.title}"));
|
|
|
|
urls = map mkUrlEntry cfg.urls;
|
|
|
|
|
|
|
|
mkQueryEntry = n: v: ''"query:${n}:${escape [ ''"'' ] v}"'';
|
|
|
|
queries = mapAttrsToList mkQueryEntry cfg.queries;
|
|
|
|
in concatStringsSep "\n"
|
|
|
|
(if versionAtLeast config.home.stateVersion "20.03" then
|
|
|
|
queries ++ urls
|
|
|
|
else
|
|
|
|
urls ++ queries) + "\n";
|
|
|
|
|
|
|
|
configFileContents = ''
|
|
|
|
max-items ${toString cfg.maxItems}
|
|
|
|
browser ${cfg.browser}
|
|
|
|
reload-threads ${toString cfg.reloadThreads}
|
2022-04-08 06:36:13 +02:00
|
|
|
auto-reload ${lib.hm.booleans.yesNo cfg.autoReload}
|
2021-04-09 22:00:52 +02:00
|
|
|
${optionalString (cfg.reloadTime != null)
|
|
|
|
(toString "reload-time ${toString cfg.reloadTime}")}
|
|
|
|
prepopulate-query-feeds yes
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2021-04-09 22:07:36 +02:00
|
|
|
meta.maintainers = [ maintainers.sumnerevans ];
|
|
|
|
|
2018-06-08 21:09:20 +02:00
|
|
|
options = {
|
|
|
|
programs.newsboat = {
|
2018-06-09 11:40:49 +02:00
|
|
|
enable = mkEnableOption "the Newsboat feed reader";
|
2018-06-08 21:09:20 +02:00
|
|
|
|
|
|
|
urls = mkOption {
|
2019-10-07 23:51:12 +02:00
|
|
|
type = types.listOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
url = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "http://example.com";
|
|
|
|
description = "Feed URL.";
|
|
|
|
};
|
|
|
|
|
|
|
|
tags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
|
|
|
example = [ "foo" "bar" ];
|
2019-10-07 23:51:12 +02:00
|
|
|
description = "Feed tags.";
|
|
|
|
};
|
|
|
|
|
|
|
|
title = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "ORF News";
|
|
|
|
description = "Feed title.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
|
|
|
example = [{
|
|
|
|
url = "http://example.com";
|
|
|
|
tags = [ "foo" "bar" ];
|
|
|
|
}];
|
2022-05-06 14:20:16 +02:00
|
|
|
description = ''
|
|
|
|
List of news feeds. Leave it empty if you want to manage feeds
|
|
|
|
imperatively, for example, using Syncthing.
|
|
|
|
'';
|
2018-06-08 21:09:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
maxItems = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
description = "Maximum number of items per feed, 0 for infinite.";
|
|
|
|
};
|
|
|
|
|
|
|
|
reloadThreads = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 5;
|
|
|
|
description = "How many threads to use for updating the feeds.";
|
|
|
|
};
|
|
|
|
|
|
|
|
autoReload = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2020-02-02 00:39:17 +01:00
|
|
|
description = ''
|
|
|
|
Whether to enable automatic reloading while newsboat is running.
|
|
|
|
'';
|
2018-06-08 21:09:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
reloadTime = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = 60;
|
|
|
|
description = "Time in minutes between reloads.";
|
|
|
|
};
|
|
|
|
|
|
|
|
browser = mkOption {
|
2018-12-04 23:42:30 +01:00
|
|
|
type = types.str;
|
2021-02-03 23:40:41 +01:00
|
|
|
default = "${pkgs.xdg-utils}/bin/xdg-open";
|
2018-06-08 21:09:20 +02:00
|
|
|
description = "External browser to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
queries = mkOption {
|
2018-12-04 23:42:30 +01:00
|
|
|
type = types.attrsOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
|
|
|
example = { "foo" = ''rssurl =~ "example.com"''; };
|
2018-06-08 21:09:20 +02:00
|
|
|
description = "A list of queries to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2020-02-02 00:39:17 +01:00
|
|
|
description = ''
|
|
|
|
Extra configuration values that will be appended to the end.
|
|
|
|
'';
|
2018-06-08 21:09:20 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2022-05-06 14:20:16 +02:00
|
|
|
assertions = [{
|
|
|
|
assertion = cfg.queries != { } -> cfg.urls != [ ];
|
|
|
|
message = ''
|
|
|
|
Cannot specify queries if urls is empty. Unset queries if you
|
|
|
|
want to manage urls imperatively.
|
|
|
|
'';
|
|
|
|
}];
|
|
|
|
|
2018-06-08 21:09:20 +02:00
|
|
|
home.packages = [ pkgs.newsboat ];
|
2021-04-09 22:00:52 +02:00
|
|
|
|
|
|
|
# Use ~/.newsboat on stateVersion < 21.05 and use ~/.config/newsboat for
|
|
|
|
# stateVersion >= 21.05.
|
|
|
|
home.file = mkIf (versionOlder config.home.stateVersion "21.05") {
|
2022-05-06 14:20:16 +02:00
|
|
|
".newsboat/urls" = mkIf (cfg.urls != [ ]) { text = urlsFileContents; };
|
2021-04-09 22:00:52 +02:00
|
|
|
".newsboat/config".text = configFileContents;
|
|
|
|
};
|
|
|
|
xdg.configFile = mkIf (versionAtLeast config.home.stateVersion "21.05") {
|
2022-05-06 14:20:16 +02:00
|
|
|
"newsboat/urls" = mkIf (cfg.urls != [ ]) { text = urlsFileContents; };
|
2021-04-09 22:00:52 +02:00
|
|
|
"newsboat/config".text = configFileContents;
|
|
|
|
};
|
2018-06-08 21:09:20 +02:00
|
|
|
};
|
|
|
|
}
|