aboutsummaryrefslogtreecommitdiff
path: root/modules/newsboat.home/default.nix
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-09-10 17:59:56 +0530
committerAkshay Nair <phenax5@gmail.com>2024-09-10 17:59:56 +0530
commitc4e395ccaaac33b1898d447b09377b8e3fd9cfa3 (patch)
treeeb94e9338f27217d2533efe494297a5066df92d3 /modules/newsboat.home/default.nix
parent3560e22fbf28f1bdf11a573421c37c15cbeabb30 (diff)
downloadnixos-config-c4e395ccaaac33b1898d447b09377b8e3fd9cfa3.tar.gz
nixos-config-c4e395ccaaac33b1898d447b09377b8e3fd9cfa3.zip
Refactor newsboat config to nix
Diffstat (limited to 'modules/newsboat.home/default.nix')
-rw-r--r--modules/newsboat.home/default.nix59
1 files changed, 59 insertions, 0 deletions
diff --git a/modules/newsboat.home/default.nix b/modules/newsboat.home/default.nix
new file mode 100644
index 0000000..aedf7db
--- /dev/null
+++ b/modules/newsboat.home/default.nix
@@ -0,0 +1,59 @@
+{ lib, pkgs, ... }:
+let
+ cfg = import ./config.nix;
+ urls = mergeFeeds [ (import ./public-feed.nix) privateFeed ];
+ privateFeed = let feedpath = ./private-feed.nix;
+ in if builtins.pathExists feedpath then import feedpath else {};
+
+ mergeFeeds = feeds: lib.attrsets.foldAttrs (value: acc:
+ if lib.isList value
+ then value ++ (if acc != null then acc else [])
+ else value // (if acc != null then acc else {})
+ ) null ([{ queries = {}; visible = []; hidden = []; }] ++ feeds);
+
+ joinLines = lib.concatStringsSep "\n";
+ joinWords = lib.concatStringsSep " ";
+
+ toUrl = url: joinWords (lib.map toString [
+ url.url
+ (lib.optional (url ? "hidden" && url.hidden) "!")
+ (lib.optional (url ? "tags") (joinWords url.tags))
+ (lib.optional (url ? "title") ''"~${url.title}"'')
+ ]);
+
+ toUrls = urls: joinLines (lib.map toUrl urls);
+
+ toQueries = queries: joinLines
+ (lib.mapAttrsToList (key: val: "\"query:${key}:${val}\"") queries);
+
+ # { raw = a; } -> a | bool -> yesno | string -> "string" | number
+ toConfigValue = val:
+ if val ? "raw" then toString val.raw
+ else if lib.isBool val then lib.hm.booleans.yesNo val
+ else if lib.isString val then ''"${val}"''
+ else toString val;
+
+ cfgFileContent = joinLines [
+ (joinLines
+ (lib.mapAttrsToList (key: val: "${key} ${toConfigValue val}") cfg.config))
+ (joinLines
+ (lib.mapAttrsToList (key: val: "bind-key ${key} ${val}") cfg.keys))
+ (joinLines
+ (lib.mapAttrsToList (key: val: "macro ${key} ${val}") cfg.macros))
+ cfg.extraConfig
+ ];
+
+ urlsFileContent = joinLines [
+ (toQueries urls.queries)
+ (toUrls urls.visible)
+ (toUrls (lib.map (x: x // { hidden = true; }) urls.hidden))
+ ];
+in {
+ home.packages = [ pkgs.newsboat ];
+
+ xdg.configFile = {
+ "newsboat/urls".text = urlsFileContent;
+ "newsboat/config".text = cfgFileContent;
+ "newsboat/opener.sh".source = ./opener.sh;
+ };
+}