{ pkgs, lib, ... }: with lib; let outlineItem = feed: ''''; outlineGroup = group: items: '' ${concatStringsSep "\n" (map outlineItem items)} ''; toOpml = cfg: '' ${cfg.title} ${concatStringsSep "\n" (mapAttrsToList outlineGroup cfg.groups)} ''; createYarrSetupScript = { username, api_key, api_url, feeds, settings }: let api = method: path: args: ''curl -i -X${method} '${api_url}${path}' --cookie 'auth=${username}:${api_key}' ${args}''; opmlFile = pkgs.writeText "rss.opml" (toOpml feeds); in pkgs.writeShellScriptBin "yarr-setup-script" '' #!/usr/bin/env sh ${api "POST" "/opml/import" "-F 'opml=@${opmlFile}' -F 'replace=true'"} && echo "Imported feeds"; ${api "PUT" "/api/settings" "--data '${builtins.toJSON settings}'"} && echo "Applied settings"; ''; in { inherit toOpml createYarrSetupScript; }