fork/home-manager
git clone https://git.julia.blue/fork/home-manager
c0f9cbcf
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6cfg = config . programs . newsboat ; 7wrapQuote = x :''" ${ x } "'' ; 8 9urlsFileContents = let 10mkUrlEntry = u : 11concatStringsSep " " ([ u . url ] ++ map wrapQuote u . tags 12++ optional ( u . title != null ) ( wrapQuote "~ ${ u . title } " )); 13urls = map mkUrlEntry cfg . urls ; 14 15mkQueryEntry = n :v :''"query: ${ n } : ${ escape [ ''"'' ] v } "'' ; 16queries = mapAttrsToList mkQueryEntry cfg . queries ; 17in concatStringsSep "\n" 18( if versionAtLeast config . home . stateVersion "20.03" then 19queries ++ urls 20else 21urls ++ queries ) + "\n" ; 22 23configFileContents = '' 24max-items ${ toString cfg . maxItems } 25browser ${ cfg . browser } 26reload-threads ${ toString cfg . reloadThreads } 27auto-reload ${ lib . hm . booleans . yesNo cfg . autoReload } 28${ optionalString ( cfg . reloadTime != null ) 29( toString "reload-time ${ toString cfg . reloadTime } " )} 30prepopulate-query-feeds yes 31 32${ cfg . extraConfig } 33'' ; 34 35in { 36meta . maintainers = [ maintainers . sumnerevans ]; 37 38options = { 39programs . newsboat = { 40enable = mkEnableOption "the Newsboat feed reader" ; 41 42urls = mkOption { 43type = types . listOf ( types . submodule { 44options = { 45url = mkOption { 46type = types . str ; 47example = "http://example.com" ; 48description = "Feed URL." ; 49}; 50 51tags = mkOption { 52type = types . listOf types . str ; 53default = [ ]; 54example = [ "foo" "bar" ]; 55description = "Feed tags." ; 56}; 57 58title = mkOption { 59type = types . nullOr types . str ; 60default = null ; 61example = "ORF News" ; 62description = "Feed title." ; 63}; 64}; 65}); 66default = [ ]; 67example = [{ 68url = "http://example.com" ; 69tags = [ "foo" "bar" ]; 70}]; 71description = '' 72List of news feeds. Leave it empty if you want to manage feeds 73imperatively, for example, using Syncthing. 74'' ; 75}; 76 77maxItems = mkOption { 78type = types . int ; 79default = 0 ; 80description = "Maximum number of items per feed, 0 for infinite." ; 81}; 82 83reloadThreads = mkOption { 84type = types . int ; 85default = 5 ; 86description = "How many threads to use for updating the feeds." ; 87}; 88 89autoReload = mkOption { 90type = types . bool ; 91default = false ; 92description = '' 93Whether to enable automatic reloading while newsboat is running. 94'' ; 95}; 96 97reloadTime = mkOption { 98type = types . nullOr types . int ; 99default = 60 ; 100description = "Time in minutes between reloads." ; 101}; 102 103browser = mkOption { 104type = types . str ; 105default = " ${ pkgs . xdg-utils } /bin/xdg-open" ; 106description = "External browser to use." ; 107}; 108 109queries = mkOption { 110type = types . attrsOf types . str ; 111default = { }; 112example = { "foo" = ''rssurl =~ "example.com"'' ; }; 113description = "A list of queries to use." ; 114}; 115 116extraConfig = mkOption { 117type = types . lines ; 118default = "" ; 119description = '' 120Extra configuration values that will be appended to the end. 121'' ; 122}; 123}; 124}; 125 126config = mkIf cfg . enable { 127assertions = [{ 128assertion = cfg . queries != { } -> cfg . urls != [ ]; 129message = '' 130Cannot specify queries if urls is empty. Unset queries if you 131want to manage urls imperatively. 132'' ; 133}]; 134 135home . packages = [ pkgs . newsboat ]; 136 137# Use ~/.newsboat on stateVersion < 21.05 and use ~/.config/newsboat for 138# stateVersion >= 21.05. 139home . file = mkIf ( versionOlder config . home . stateVersion "21.05" ) { 140".newsboat/urls" = mkIf ( cfg . urls != [ ]) { text = urlsFileContents ; }; 141".newsboat/config" . text = configFileContents ; 142}; 143xdg . configFile = mkIf ( versionAtLeast config . home . stateVersion "21.05" ) { 144"newsboat/urls" = mkIf ( cfg . urls != [ ]) { text = urlsFileContents ; }; 145"newsboat/config" . text = configFileContents ; 146}; 147}; 148}