tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
fetchzip: cleanup and improve metrics a bit
Jan Malakhovski
2 years ago
9dcecbdb
672efa69
+21
-34
1 changed file
expand all
collapse all
unified
split
pkgs
build-support
fetchzip
default.nix
+21
-34
pkgs/build-support/fetchzip/default.nix
···
7
7
8
8
{ lib, fetchurl, unzip, glibcLocalesUtf8 }:
9
9
10
10
-
{ # Optionally move the contents of the unpacked tree up one level.
11
11
-
stripRoot ? true
10
10
+
{ name ? "source"
12
11
, url ? ""
13
12
, urls ? []
14
14
-
, extraPostFetch ? ""
13
13
+
, nativeBuildInputs ? []
15
14
, postFetch ? ""
16
16
-
, name ? "source"
17
17
-
, pname ? ""
18
18
-
, version ? ""
19
19
-
, nativeBuildInputs ? [ ]
20
20
-
, # Allows to set the extension for the intermediate downloaded
21
21
-
# file. This can be used as a hint for the unpackCmdHooks to select
22
22
-
# an appropriate unpacking tool.
23
23
-
extension ? null
24
24
-
, ... } @ args:
15
15
+
, extraPostFetch ? ""
25
16
17
17
+
# Optionally move the contents of the unpacked tree up one level.
18
18
+
, stripRoot ? true
19
19
+
# Allows to set the extension for the intermediate downloaded
20
20
+
# file. This can be used as a hint for the unpackCmdHooks to select
21
21
+
# an appropriate unpacking tool.
22
22
+
, extension ? null
26
23
27
27
-
lib.warnIf (extraPostFetch != "") "use 'postFetch' instead of 'extraPostFetch' with 'fetchzip' and 'fetchFromGitHub'."
24
24
+
# the rest are given to fetchurl as is
25
25
+
, ... } @ args:
26
26
+
27
27
+
assert (extraPostFetch != "") -> lib.warn "use 'postFetch' instead of 'extraPostFetch' with 'fetchzip' and 'fetchFromGitHub'." true;
28
28
29
29
-
(let
29
29
+
let
30
30
tmpFilename =
31
31
if extension != null
32
32
then "download.${extension}"
33
33
else baseNameOf (if url != "" then url else builtins.head urls);
34
34
in
35
35
36
36
-
fetchurl ((
37
37
-
if (pname != "" && version != "") then
38
38
-
{
39
39
-
name = "${pname}-${version}";
40
40
-
inherit pname version;
41
41
-
}
42
42
-
else
43
43
-
{ inherit name; }
44
44
-
) // {
36
36
+
fetchurl ({
37
37
+
inherit name;
45
38
recursiveHash = true;
46
39
47
40
downloadToTemp = true;
···
61
54
mv "$downloadedFile" "$renamed"
62
55
unpackFile "$renamed"
63
56
chmod -R +w "$unpackDir"
64
64
-
''
65
65
-
+ (if stripRoot then ''
57
57
+
'' + (if stripRoot then ''
66
58
if [ $(ls -A "$unpackDir" | wc -l) != 1 ]; then
67
59
echo "error: zip file must contain a single file or directory."
68
60
echo "hint: Pass stripRoot=false; to fetchzip to assume flat list of files."
···
75
67
mv "$unpackDir/$fn" "$out"
76
68
'' else ''
77
69
mv "$unpackDir" "$out"
78
78
-
'')
79
79
-
+ ''
70
70
+
'') + ''
80
71
${postFetch}
81
81
-
'' + ''
82
72
${extraPostFetch}
83
83
-
''
84
84
-
85
85
-
# Remove non-owner write permissions
86
86
-
# Fixes https://github.com/NixOS/nixpkgs/issues/38649
87
87
-
+ ''
88
73
chmod 755 "$out"
89
74
'';
90
90
-
} // removeAttrs args [ "stripRoot" "extraPostFetch" "postFetch" "extension" "nativeBuildInputs" ]))
75
75
+
# ^ Remove non-owner write permissions
76
76
+
# Fixes https://github.com/NixOS/nixpkgs/issues/38649
77
77
+
} // removeAttrs args [ "stripRoot" "extraPostFetch" "postFetch" "extension" "nativeBuildInputs" ])