From aa7e1dfd339dfb1cfcd5acf8760ec74eb865c69b Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 28 Sep 2024 09:55:12 +0000 Subject: [PATCH] refactor: modules/data/feeds: fewer file-level inherits --- modules/data/feeds/default.nix | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/modules/data/feeds/default.nix b/modules/data/feeds/default.nix index 1fbda2830..7f87397da 100644 --- a/modules/data/feeds/default.nix +++ b/modules/data/feeds/default.nix @@ -1,18 +1,13 @@ { lib, sane-lib, ... }: - let - inherit (builtins) concatLists concatStringsSep foldl' fromJSON map readDir readFile; - inherit (lib) hasSuffix listToAttrs mapAttrsToList removeSuffix splitString; - inherit (sane-lib) enumerateFilePaths; - # 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. # Type: feedFromSourcePath :: String -> { name = String; value = feed; } feedFromSourcePath = json-path: - assert hasSuffix "/default.json" json-path; + assert lib.hasSuffix "/default.json" json-path; let - canonical-name = removeSuffix "/default.json" json-path; + canonical-name = lib.removeSuffix "/default.json" json-path; default-url = "https://${canonical-name}"; feed-details = { url = default-url; } // (tryImportJson (./sources/${json-path})); in { name = canonical-name; value = mkFeed feed-details; }; @@ -25,13 +20,13 @@ let # or {} if the path is empty. tryImportJson = path: let - as-str = readFile path; + as-str = builtins.readFile path; in if as-str == "" then {} else - fromJSON as-str; + builtins.fromJSON as-str; - sources = enumerateFilePaths ./sources; + sources = sane-lib.enumerateFilePaths ./sources; in - listToAttrs (map feedFromSourcePath sources) + lib.listToAttrs (builtins.map feedFromSourcePath sources)