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