2023-05-14 09:50:01 +00:00
|
|
|
{ lib, sane-lib, ... }:
|
2023-01-10 03:52:33 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
inherit (builtins) concatLists concatStringsSep foldl' fromJSON map readDir readFile;
|
2023-01-10 10:53:55 +00:00
|
|
|
inherit (lib) hasSuffix listToAttrs mapAttrsToList removeSuffix splitString;
|
2023-05-14 09:50:01 +00:00
|
|
|
inherit (sane-lib) enumerateFilePaths;
|
2023-01-10 03:52:33 +00:00
|
|
|
|
|
|
|
# given a path to a .json file relative to sources, construct the best feed object we can.
|
|
|
|
# the .json file could be empty, in which case we make assumptions about the feed based
|
|
|
|
# on its fs path.
|
2023-01-10 10:53:55 +00:00
|
|
|
# Type: feedFromSourcePath :: String -> { name = String; value = feed; }
|
2023-01-10 03:52:33 +00:00
|
|
|
feedFromSourcePath = json-path:
|
2023-01-10 10:53:55 +00:00
|
|
|
assert hasSuffix "/default.json" json-path;
|
2023-01-10 03:52:33 +00:00
|
|
|
let
|
2023-01-10 10:53:55 +00:00
|
|
|
canonical-name = removeSuffix "/default.json" json-path;
|
2023-01-10 03:52:33 +00:00
|
|
|
default-url = "https://${canonical-name}";
|
|
|
|
feed-details = { url = default-url; } // (tryImportJson (./sources/${json-path}));
|
2023-01-10 10:53:55 +00:00
|
|
|
in { name = canonical-name; value = mkFeed feed-details; };
|
2023-01-10 03:52:33 +00:00
|
|
|
|
|
|
|
# TODO: for now, feeds are just ordinary Attrs.
|
|
|
|
# in the future, we'd like to set them up with an update script.
|
|
|
|
mkFeed = { url, ... }@details: details;
|
|
|
|
|
|
|
|
# return an AttrSet representing the json at the provided path,
|
|
|
|
# or {} if the path is empty.
|
|
|
|
tryImportJson = path:
|
|
|
|
let
|
|
|
|
as-str = readFile path;
|
|
|
|
in
|
|
|
|
if as-str == "" then
|
|
|
|
{}
|
|
|
|
else
|
|
|
|
fromJSON as-str;
|
|
|
|
|
|
|
|
sources = enumerateFilePaths ./sources;
|
|
|
|
in
|
2023-01-10 10:53:55 +00:00
|
|
|
listToAttrs (map feedFromSourcePath sources)
|