newsboat: use $XDG_CONFIG_HOME/newsboat

As of Newsboat 2.19, configuration using XDG_CONFIG_HOME/newsboat is
supported:
https://newsboat.org/releases/2.19/docs/newsboat.html#_xdg_base_directory_support

This is a continuation of #1331 and includes gating logic so that the
change doesn't happen until state version 21.05.

Supersedes and Closes #1331
This commit is contained in:
Sumner Evans 2021-04-09 14:00:52 -06:00 committed by Robert Helgesson
parent 18930aaf75
commit f7159a0f76
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 75 additions and 25 deletions

View file

@ -179,4 +179,5 @@ The state version in this release includes the changes below. These
changes are only active if the `home.stateVersion` option is set to
"21.05" or later.
* Nothing has happened.
* The `newsboat` module now stores generated configuration in
`$XDG_CONFIG_HOME/newsboat`.

View file

@ -6,6 +6,32 @@ let
cfg = config.programs.newsboat;
wrapQuote = x: ''"${x}"'';
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}
auto-reload ${if cfg.autoReload then "yes" else "no"}
${optionalString (cfg.reloadTime != null)
(toString "reload-time ${toString cfg.reloadTime}")}
prepopulate-query-feeds yes
${cfg.extraConfig}
'';
in {
options = {
programs.newsboat = {
@ -94,30 +120,16 @@ in {
config = mkIf cfg.enable {
home.packages = [ pkgs.newsboat ];
home.file.".newsboat/urls".text = 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";
home.file.".newsboat/config".text = ''
max-items ${toString cfg.maxItems}
browser ${cfg.browser}
reload-threads ${toString cfg.reloadThreads}
auto-reload ${if cfg.autoReload then "yes" else "no"}
${optionalString (cfg.reloadTime != null)
(toString "reload-time ${toString cfg.reloadTime}")}
prepopulate-query-feeds yes
${cfg.extraConfig}
'';
# Use ~/.newsboat on stateVersion < 21.05 and use ~/.config/newsboat for
# stateVersion >= 21.05.
home.file = mkIf (versionOlder config.home.stateVersion "21.05") {
".newsboat/urls".text = urlsFileContents;
".newsboat/config".text = configFileContents;
};
xdg.configFile = mkIf (versionAtLeast config.home.stateVersion "21.05") {
"newsboat/urls".text = urlsFileContents;
"newsboat/config".text = configFileContents;
};
};
}

View file

@ -1,4 +1,5 @@
{
newsboat-basics = ./newsboat-basics.nix;
newsboat-basics-2003 = ./newsboat-basics-2003.nix;
newsboat-basics-2105 = ./newsboat-basics-2105.nix;
}

View file

@ -0,0 +1,36 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
home.stateVersion = "21.05";
programs.newsboat = {
enable = true;
urls = [
{
url = "http://example.org/feed.xml";
tags = [ "tag1" "tag2" ];
title = "Cool feed";
}
{ url = "http://example.org/feed2.xml"; }
];
queries = { "foo" = ''rssurl =~ "example.com"''; };
};
nixpkgs.overlays = [
(self: super: { newsboat = pkgs.writeScriptBin "dummy-newsboat" ""; })
];
# The format didn't change since 20.03, just the location.
nmt.script = ''
assertFileContent \
home-files/.config/newsboat/urls \
${./newsboat-basics-urls-2003.txt}
'';
};
}