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 {
#### my own, non-upstreamable packages:
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-rpi4 = callPackage ../pkgs/tow-boot-rpi4 { };
bootpart-uefi-x86_64 = callPackage ../pkgs/bootpart-uefi-x86_64 { };

View File

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