diff --git a/modules/programs/newsboat.nix b/modules/programs/newsboat.nix index 84c64dfa..19fec642 100644 --- a/modules/programs/newsboat.nix +++ b/modules/programs/newsboat.nix @@ -14,10 +14,32 @@ in enable = mkEnableOption "the Newsboat feed reader"; urls = mkOption { - type = types.listOf types.attrs; + 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; + default = []; + example = ["foo" "bar"]; + description = "Feed tags."; + }; + + title = mkOption { + type = types.nullOr types.str; + default = null; + example = "ORF News"; + description = "Feed title."; + }; + }; + }); default = []; example = [{url = "http://example.com"; tags = ["foo" "bar"];}]; - description = "List of urls and tokens."; + description = "List of news feeds."; }; maxItems = mkOption { @@ -71,19 +93,18 @@ in home.packages = [ pkgs.newsboat ]; home.file.".newsboat/urls".text = let - urls = builtins.concatStringsSep "\n" ( - map (u: builtins.concatStringsSep " " ([u.url] ++ (map wrapQuote u.tags))) - cfg.urls); - queries = builtins.concatStringsSep "\n" ( - mapAttrsToList (n: v: "\"query:${n}:${escape ["\""] v}\"") cfg.queries); + 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" (urls ++ queries) + "\n"; - '' - ${urls} - - ${queries} - ''; home.file.".newsboat/config".text = '' max-items ${toString cfg.maxItems} browser ${cfg.browser} diff --git a/tests/default.nix b/tests/default.nix index 4bda0474..ecb98e14 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -46,6 +46,7 @@ import nmt { // import ./modules/programs/alacritty // import ./modules/programs/bash // import ./modules/programs/gpg + // import ./modules/programs/newsboat // import ./modules/programs/ssh // import ./modules/programs/tmux // import ./modules/programs/zsh; diff --git a/tests/modules/programs/newsboat/default.nix b/tests/modules/programs/newsboat/default.nix new file mode 100644 index 00000000..a9b15a44 --- /dev/null +++ b/tests/modules/programs/newsboat/default.nix @@ -0,0 +1,3 @@ +{ + newsboat-basics = ./newsboat-basics.nix; +} diff --git a/tests/modules/programs/newsboat/newsboat-basics-urls.txt b/tests/modules/programs/newsboat/newsboat-basics-urls.txt new file mode 100644 index 00000000..7f084961 --- /dev/null +++ b/tests/modules/programs/newsboat/newsboat-basics-urls.txt @@ -0,0 +1,3 @@ +http://example.org/feed.xml "tag1" "tag2" "~Cool feed" +http://example.org/feed2.xml +"query:foo:rssurl =~ \"example.com\"" diff --git a/tests/modules/programs/newsboat/newsboat-basics.nix b/tests/modules/programs/newsboat/newsboat-basics.nix new file mode 100644 index 00000000..49a54f6d --- /dev/null +++ b/tests/modules/programs/newsboat/newsboat-basics.nix @@ -0,0 +1,39 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + 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" ""; + }) + ]; + + nmt.script = '' + assertFileContent \ + home-files/.newsboat/urls \ + ${./newsboat-basics-urls.txt} + ''; + }; +}