pkgs/feeds: rework to use recurseIntoAttrs

this is closer to what upstream seems to prefer, but i'm still a little
unsure.
This commit is contained in:
Colin 2023-03-11 09:59:53 +00:00
parent dc1cd7a9a5
commit 4fe6f2aab3
2 changed files with 45 additions and 44 deletions

View File

@ -4,7 +4,7 @@
sane = rec { sane = rec {
#### my own, non-upstreamable packages: #### my own, non-upstreamable packages:
sane-scripts = callPackage ../pkgs/sane-scripts { }; sane-scripts = callPackage ../pkgs/sane-scripts { };
feeds = callPackage ../pkgs/feeds { }; feeds = recurseIntoAttrs (callPackage ../pkgs/feeds { });
tow-boot-pinephone = callPackage ../pkgs/tow-boot-pinephone { }; tow-boot-pinephone = callPackage ../pkgs/tow-boot-pinephone { };
tow-boot-rpi4 = callPackage ../pkgs/tow-boot-rpi4 { }; tow-boot-rpi4 = callPackage ../pkgs/tow-boot-rpi4 { };
bootpart-uefi-x86_64 = callPackage ../pkgs/bootpart-uefi-x86_64 { }; bootpart-uefi-x86_64 = callPackage ../pkgs/bootpart-uefi-x86_64 { };

View File

@ -1,49 +1,50 @@
{ lib { lib
, pkgs , callPackage
, writeShellScript
}: }:
(lib.makeScope pkgs.newScope (self: let
let # TODO: dependency-inject this.
# TODO: dependency-inject this. sane-data = import ../../modules/data { inherit lib; };
sane-data = import ../../modules/data { inherit lib; }; template = callPackage ./template.nix;
template = self.callPackage ./template.nix; feed-pkgs = lib.mapAttrs
feed-pkgs = lib.mapAttrs (name: feed-details: template {
(name: feed-details: template { feedName = name;
feedName = name; jsonPath = "modules/data/feeds/sources/${name}/default.json";
jsonPath = "modules/data/feeds/sources/${name}/default.json"; inherit (feed-details) url;
inherit (feed-details) url; })
}) sane-data.feeds;
sane-data.feeds; update-scripts = lib.mapAttrsToList
update-scripts = lib.mapAttrsToList (name: feed: builtins.concatStringsSep " " feed.passthru.updateScript)
(name: feed: builtins.concatStringsSep " " feed.passthru.updateScript) feed-pkgs;
feed-pkgs; in {
in inherit feed-pkgs;
feed-pkgs // { passthru = {
passthru.updateScript = pkgs.writeShellScript updateScript = writeShellScript
"feeds-update" "feeds-update"
(builtins.concatStringsSep "\n" update-scripts); (builtins.concatStringsSep "\n" update-scripts);
passthru.initFeedScript = pkgs.writeShellScript initFeedScript = writeShellScript
"init-feed" "init-feed"
'' ''
# this is the `nix run '.#init-feed' <url>` script` # this is the `nix run '.#init-feed' <url>` script`
sources_dir=modules/data/feeds/sources sources_dir=modules/data/feeds/sources
# prettify the URL, by default # prettify the URL, by default
name=$( \ name=$( \
echo "$1" \ echo "$1" \
| sed 's|^https://||' \ | sed 's|^https://||' \
| sed 's|^http://||' \ | sed 's|^http://||' \
| sed 's|^www\.||' \ | sed 's|^www\.||' \
| sed 's|/+$||' \ | sed 's|/+$||' \
) )
json_path="$sources_dir/$name/default.json" json_path="$sources_dir/$name/default.json"
# the name could have slashes in it, so we want to mkdir -p that # the name could have slashes in it, so we want to mkdir -p that
# but in a way where the least could go wrong. # but in a way where the least could go wrong.
pushd "$sources_dir"; mkdir -p "$name"; popd pushd "$sources_dir"; mkdir -p "$name"; popd
${./update.py} "$name" "$json_path" ${./update.py} "$name" "$json_path"
cat "$json_path" cat "$json_path"
''; '';
} };
)) }