pkgs/den-http-get-updater: support providing target hash

This commit is contained in:
Wroclaw 2025-04-07 21:16:20 +02:00
parent 890260024f
commit 517ca95d8d

View file

@ -21,6 +21,8 @@
# file: string; # file: string;
# attrpath: string[]' # attrpath: string[]'
# }; # };
# prefetchHash: string?;
# targetHash: string?;
# }[] # }[]
# #
prefetchList ? [], prefetchList ? [],
@ -34,6 +36,8 @@
contentParser ? "echo \"$newVersion\"", contentParser ? "echo \"$newVersion\"",
unpack ? true, unpack ? true,
hashAlgo ? "sha256",
hashFormat ? "sri",
name ? if unpack then "source" else null, name ? if unpack then "source" else null,
}: }:
@ -48,7 +52,7 @@ let
); );
assert lib.isAttrs x.prefetchUrlLocation && lib.isString x.prefetchUrlLocation.attrpath or null; assert lib.isAttrs x.prefetchUrlLocation && lib.isString x.prefetchUrlLocation.attrpath or null;
rec { rec {
inherit fileLocation; inherit fileLocation hashAlgo hashFormat;
mark = builtins.hashString "sha256" x.previousHash; mark = builtins.hashString "sha256" x.previousHash;
markRegexEscape = lib.escapeRegex mark; markRegexEscape = lib.escapeRegex mark;
realFileLocation = builtins.toString x.fileLocation or fileLocation; realFileLocation = builtins.toString x.fileLocation or fileLocation;
@ -123,7 +127,12 @@ writeScript "den-http-get-updater" (''
prefetchSucceeded=1 prefetchSucceeded=1
for url in "''${prefetchUrls[@]}"; do for url in "''${prefetchUrls[@]}"; do
echo "trying prefetch '$url'..."; echo "trying prefetch '$url'...";
expectedHash=$(nix-prefetch-url "$url" ${nixUnpack} ${nixName}) expectedHash=$(nix-prefetch-url "$url" ${nixUnpack} ${nixName} --type "${hashAlgo}")
expectedHash=$(nix --extra-experimental-features "nix-command" hash convert \
--hash-algo "${hashAlgo}" \
--to "${hashFormat}" \
"$expectedHash"
)
if [[ -n $expectedHash ]]; then if [[ -n $expectedHash ]]; then
echo "prefetch succeeded!" echo "prefetch succeeded!"
echo "hash: $expectedHash" echo "hash: $expectedHash"