2020-04-24 23:36:52 +00:00
|
|
|
# This function downloads and unpacks an archive file, such as a zip
|
|
|
|
# or tar file. This is primarily useful for dynamically generated
|
|
|
|
# archives, such as GitHub's /archive URLs, where the unpacked content
|
|
|
|
# of the zip file doesn't change, but the zip file itself may
|
|
|
|
# (e.g. due to minor changes in the compression algorithm, or changes
|
|
|
|
# in timestamps).
|
|
|
|
|
2022-07-14 12:49:19 +00:00
|
|
|
{ lib, fetchurl, unzip, glibcLocalesUtf8 }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
{ # Optionally move the contents of the unpacked tree up one level.
|
|
|
|
stripRoot ? true
|
2021-04-08 16:26:57 +00:00
|
|
|
, url ? ""
|
|
|
|
, urls ? []
|
2020-04-24 23:36:52 +00:00
|
|
|
, extraPostFetch ? ""
|
2022-06-16 17:23:12 +00:00
|
|
|
, postFetch ? ""
|
2020-04-24 23:36:52 +00:00
|
|
|
, name ? "source"
|
2022-03-05 16:20:37 +00:00
|
|
|
, nativeBuildInputs ? [ ]
|
2021-08-18 13:19:15 +00:00
|
|
|
, # Allows to set the extension for the intermediate downloaded
|
|
|
|
# file. This can be used as a hint for the unpackCmdHooks to select
|
|
|
|
# an appropriate unpacking tool.
|
|
|
|
extension ? null
|
2020-04-24 23:36:52 +00:00
|
|
|
, ... } @ args:
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
|
|
|
|
lib.warnIf (extraPostFetch != "") "use 'postFetch' instead of 'extraPostFetch' with 'fetchzip' and 'fetchFromGitHub'."
|
2021-04-08 16:26:57 +00:00
|
|
|
(fetchurl (let
|
2021-08-18 13:19:15 +00:00
|
|
|
tmpFilename =
|
|
|
|
if extension != null
|
|
|
|
then "download.${extension}"
|
|
|
|
else baseNameOf (if url != "" then url else builtins.head urls);
|
2021-04-08 16:26:57 +00:00
|
|
|
in {
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit name;
|
|
|
|
|
|
|
|
recursiveHash = true;
|
|
|
|
|
|
|
|
downloadToTemp = true;
|
|
|
|
|
2022-07-14 12:49:19 +00:00
|
|
|
# Have to pull in glibcLocalesUtf8 for unzip in setup-hook.sh to handle
|
|
|
|
# UTF-8 aware locale:
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/176225#issuecomment-1146617263
|
|
|
|
nativeBuildInputs = [ unzip glibcLocalesUtf8 ] ++ nativeBuildInputs;
|
2022-03-05 16:20:37 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
postFetch =
|
|
|
|
''
|
|
|
|
unpackDir="$TMPDIR/unpack"
|
|
|
|
mkdir "$unpackDir"
|
|
|
|
cd "$unpackDir"
|
|
|
|
|
2021-08-18 13:19:15 +00:00
|
|
|
renamed="$TMPDIR/${tmpFilename}"
|
2020-04-24 23:36:52 +00:00
|
|
|
mv "$downloadedFile" "$renamed"
|
|
|
|
unpackFile "$renamed"
|
2021-09-18 10:52:07 +00:00
|
|
|
chmod -R +w "$unpackDir"
|
2020-04-24 23:36:52 +00:00
|
|
|
''
|
|
|
|
+ (if stripRoot then ''
|
|
|
|
if [ $(ls "$unpackDir" | wc -l) != 1 ]; then
|
|
|
|
echo "error: zip file must contain a single file or directory."
|
|
|
|
echo "hint: Pass stripRoot=false; to fetchzip to assume flat list of files."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fn=$(cd "$unpackDir" && echo *)
|
|
|
|
if [ -f "$unpackDir/$fn" ]; then
|
|
|
|
mkdir $out
|
|
|
|
fi
|
|
|
|
mv "$unpackDir/$fn" "$out"
|
|
|
|
'' else ''
|
|
|
|
mv "$unpackDir" "$out"
|
2020-11-30 08:33:03 +00:00
|
|
|
'')
|
2021-02-13 14:23:35 +00:00
|
|
|
+ ''
|
2022-06-16 17:23:12 +00:00
|
|
|
${postFetch}
|
|
|
|
'' + ''
|
2021-02-13 14:23:35 +00:00
|
|
|
${extraPostFetch}
|
|
|
|
''
|
2022-06-16 17:23:12 +00:00
|
|
|
|
2021-02-13 14:23:35 +00:00
|
|
|
# Remove non-owner write permissions
|
2020-11-30 08:33:03 +00:00
|
|
|
# Fixes https://github.com/NixOS/nixpkgs/issues/38649
|
|
|
|
+ ''
|
2021-02-13 14:23:35 +00:00
|
|
|
chmod 755 "$out"
|
2020-11-30 08:33:03 +00:00
|
|
|
'';
|
2022-06-16 17:23:12 +00:00
|
|
|
} // removeAttrs args [ "stripRoot" "extraPostFetch" "postFetch" "extension" "nativeBuildInputs" ]))
|