From 4fe6f2aab36b85ee84fc627e149908d13e2b2e05 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 11 Mar 2023 09:59:53 +0000 Subject: [PATCH] pkgs/feeds: rework to use `recurseIntoAttrs` this is closer to what upstream seems to prefer, but i'm still a little unsure. --- overlays/pkgs.nix | 2 +- pkgs/feeds/default.nix | 87 +++++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/overlays/pkgs.nix b/overlays/pkgs.nix index fbedec79..354a52d8 100644 --- a/overlays/pkgs.nix +++ b/overlays/pkgs.nix @@ -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 { }; diff --git a/pkgs/feeds/default.nix b/pkgs/feeds/default.nix index 6aeead05..9538e531 100644 --- a/pkgs/feeds/default.nix +++ b/pkgs/feeds/default.nix @@ -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' ` 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' ` 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" + ''; + }; +}