From f7159a0f7655106ecec68c838bebbed0b39a2215 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Fri, 9 Apr 2021 14:00:52 -0600 Subject: [PATCH] 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 --- doc/release-notes/rl-2105.adoc | 3 +- modules/programs/newsboat.nix | 60 +++++++++++-------- tests/modules/programs/newsboat/default.nix | 1 + .../newsboat/newsboat-basics-2105.nix | 36 +++++++++++ 4 files changed, 75 insertions(+), 25 deletions(-) create mode 100644 tests/modules/programs/newsboat/newsboat-basics-2105.nix diff --git a/doc/release-notes/rl-2105.adoc b/doc/release-notes/rl-2105.adoc index 29244aace..918b863b2 100644 --- a/doc/release-notes/rl-2105.adoc +++ b/doc/release-notes/rl-2105.adoc @@ -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`. diff --git a/modules/programs/newsboat.nix b/modules/programs/newsboat.nix index 19d4c775e..128495812 100644 --- a/modules/programs/newsboat.nix +++ b/modules/programs/newsboat.nix @@ -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; + }; }; } diff --git a/tests/modules/programs/newsboat/default.nix b/tests/modules/programs/newsboat/default.nix index f12f640ef..b40751c0e 100644 --- a/tests/modules/programs/newsboat/default.nix +++ b/tests/modules/programs/newsboat/default.nix @@ -1,4 +1,5 @@ { newsboat-basics = ./newsboat-basics.nix; newsboat-basics-2003 = ./newsboat-basics-2003.nix; + newsboat-basics-2105 = ./newsboat-basics-2105.nix; } diff --git a/tests/modules/programs/newsboat/newsboat-basics-2105.nix b/tests/modules/programs/newsboat/newsboat-basics-2105.nix new file mode 100644 index 000000000..e7a17c5d7 --- /dev/null +++ b/tests/modules/programs/newsboat/newsboat-basics-2105.nix @@ -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} + ''; + }; +}