define a per-feed update script
it currently has to be run manually: ``` ./pkgs/feeds/update.sh <...> ``` it looks like `nix-update` might not really support flakes
This commit is contained in:
parent
cdc881e887
commit
965d7eedbb
|
@ -2,21 +2,19 @@
|
|||
|
||||
let
|
||||
inherit (builtins) concatLists concatStringsSep foldl' fromJSON map readDir readFile;
|
||||
inherit (lib) init mapAttrsToList removePrefix removeSuffix splitString;
|
||||
inherit (lib.attrsets) recursiveUpdate setAttrByPath;
|
||||
inherit (lib.filesystem) listFilesRecursive;
|
||||
inherit (lib) hasSuffix listToAttrs mapAttrsToList removeSuffix splitString;
|
||||
|
||||
# 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 -> { path = [String]; value = feed; }
|
||||
# Type: feedFromSourcePath :: String -> { name = String; value = feed; }
|
||||
feedFromSourcePath = json-path:
|
||||
assert hasSuffix "/default.json" json-path;
|
||||
let
|
||||
canonical-name = removeSuffix "/default" (lib.removeSuffix ".json" json-path);
|
||||
canonical-name = removeSuffix "/default.json" json-path;
|
||||
default-url = "https://${canonical-name}";
|
||||
attr-path = splitString "/" canonical-name;
|
||||
feed-details = { url = default-url; } // (tryImportJson (./sources/${json-path}));
|
||||
in { path = attr-path; value = mkFeed feed-details; };
|
||||
in { name = canonical-name; value = mkFeed feed-details; };
|
||||
|
||||
# TODO: for now, feeds are just ordinary Attrs.
|
||||
# in the future, we'd like to set them up with an update script.
|
||||
|
@ -49,10 +47,5 @@ let
|
|||
)
|
||||
(readDir base)
|
||||
);
|
||||
|
||||
# like listToAttrs, except takes { path, value } pairs instead of { name, value } pairs.
|
||||
# Type: listToAttrsByPath :: [{ path = [String]; value = Any; }] -> Attrs
|
||||
listToAttrsByPath = items:
|
||||
foldl' (acc: { path, value }: recursiveUpdate acc (setAttrByPath path value)) {} items;
|
||||
in
|
||||
listToAttrsByPath (map feedFromSourcePath sources)
|
||||
listToAttrs (map feedFromSourcePath sources)
|
||||
|
|
17
pkgs/feeds/default.nix
Normal file
17
pkgs/feeds/default.nix
Normal file
|
@ -0,0 +1,17 @@
|
|||
{ lib
|
||||
, pkgs
|
||||
}:
|
||||
|
||||
(lib.makeScope pkgs.newScope (self:
|
||||
let
|
||||
# TODO: dependency-inject this.
|
||||
sane-data = import ../../modules/data { inherit lib; };
|
||||
template = self.callPackage ./template.nix;
|
||||
in lib.mapAttrs
|
||||
(name: feed-details: template {
|
||||
feedName = name;
|
||||
jsonPath = "modules/data/feeds/sources/${name}/default.json";
|
||||
inherit (feed-details) url;
|
||||
})
|
||||
sane-data.feeds
|
||||
))
|
28
pkgs/feeds/template.nix
Normal file
28
pkgs/feeds/template.nix
Normal file
|
@ -0,0 +1,28 @@
|
|||
{ lib
|
||||
, stdenv
|
||||
, callPackage
|
||||
, fetchurl
|
||||
# feed-specific args
|
||||
, feedName
|
||||
, jsonPath
|
||||
, url
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
pname = feedName;
|
||||
version = "20230112";
|
||||
src = fetchurl {
|
||||
inherit url;
|
||||
};
|
||||
passthru.updateScript = [ ./update.sh url jsonPath ];
|
||||
# passthru.updateScript = callPackage ./update.nix {
|
||||
# inherit url jsonPath;
|
||||
# };
|
||||
meta = {
|
||||
description = "metadata about any feeds available at ${feedName}";
|
||||
homepage = feedName;
|
||||
maintainers = with lib.maintainers; [ colinsane ];
|
||||
platforms = lib.platforms.all;
|
||||
};
|
||||
}
|
||||
|
18
pkgs/feeds/update.nix
Normal file
18
pkgs/feeds/update.nix
Normal file
|
@ -0,0 +1,18 @@
|
|||
{ lib
|
||||
, curl
|
||||
, jq
|
||||
, runtimeShell
|
||||
, writeScript
|
||||
# feed-specific args
|
||||
, jsonPath
|
||||
, url
|
||||
}:
|
||||
|
||||
let
|
||||
apiQuery = "https://feedsearch.dev/api/v1/search?url=${url}";
|
||||
in
|
||||
writeScript "update-feed" ''
|
||||
#!${runtimeShell}
|
||||
PATH=${lib.makeBinPath [ curl jq ]}
|
||||
curl -X GET '${apiQuery}' | jq '.[-1]' > '${jsonPath}'
|
||||
''
|
10
pkgs/feeds/update.sh
Executable file
10
pkgs/feeds/update.sh
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p curl jq
|
||||
|
||||
set -xeu -o pipefail
|
||||
|
||||
url="$1"
|
||||
jsonPath="$2"
|
||||
|
||||
apiQuery="https://feedsearch.dev/api/v1/search?url=$url"
|
||||
curl -X GET "$apiQuery" | jq '.[-1]' > "$jsonPath"
|
|
@ -1,6 +1,7 @@
|
|||
(next: prev: rec {
|
||||
#### my own, non-upstreamable packages:
|
||||
sane-scripts = prev.callPackage ./sane-scripts { };
|
||||
feeds = prev.callPackage ./feeds { };
|
||||
tow-boot-pinephone = prev.callPackage ./tow-boot-pinephone { };
|
||||
tow-boot-rpi4 = prev.callPackage ./tow-boot-rpi4 { };
|
||||
bootpart-uefi-x86_64 = prev.callPackage ./bootpart-uefi-x86_64 { };
|
||||
|
|
Loading…
Reference in New Issue
Block a user