Skip to content

Commit 49ca901

Browse files
committed
zon2nix: follow nixfmt-rfc-style
1 parent 5ed0d14 commit 49ca901

File tree

1 file changed

+81
-35
lines changed

1 file changed

+81
-35
lines changed

tools/zon2nix.nix

+81-35
Original file line numberDiff line numberDiff line change
@@ -27,48 +27,94 @@ writeShellApplication {
2727
cat <<'EOF'
2828
# generated by zon2nix (https://github.com/Cloudef/zig2nix)
2929
30-
{ lib, linkFarm, fetchurl, fetchgit, runCommandLocal, zig, name ? "zig-packages" }:
30+
{
31+
lib,
32+
linkFarm,
33+
fetchurl,
34+
fetchgit,
35+
runCommandLocal,
36+
zig,
37+
name ? "zig-packages",
38+
}:
3139
3240
with builtins;
3341
with lib;
3442
3543
let
36-
unpackZigArtifact = { name, artifact }: runCommandLocal name {
37-
nativeBuildInputs = [ zig ];
38-
} ${"''"}
39-
hash="$(zig fetch --global-cache-dir "$TMPDIR" ''${artifact})"
40-
mv "$TMPDIR/p/$hash" "$out"
41-
chmod 755 "$out"
42-
${"''"};
44+
unpackZigArtifact =
45+
{ name, artifact }:
46+
runCommandLocal name
47+
{
48+
nativeBuildInputs = [ zig ];
49+
}
50+
${"''"}
51+
hash="$(zig fetch --global-cache-dir "$TMPDIR" ''${artifact})"
52+
mv "$TMPDIR/p/$hash" "$out"
53+
chmod 755 "$out"
54+
${"''"};
4355
44-
fetchZig = { name, url, hash }: let
45-
artifact = fetchurl { inherit url hash; };
46-
in unpackZigArtifact { inherit name artifact; };
56+
fetchZig =
57+
{
58+
name,
59+
url,
60+
hash,
61+
}:
62+
let
63+
artifact = fetchurl { inherit url hash; };
64+
in
65+
unpackZigArtifact { inherit name artifact; };
4766
48-
fetchGitZig = { name, url, hash }: let
49-
parts = splitString "#" url;
50-
url_base = elemAt parts 0;
51-
url_without_query = elemAt (splitString "?" url_base) 0;
52-
rev_base = elemAt parts 1;
53-
rev = if match "^[a-fA-F0-9]{40}$" rev_base != null then rev_base else "refs/heads/''${rev_base}";
54-
in fetchgit {
55-
inherit name rev hash;
56-
url = url_without_query;
57-
deepClone = false;
58-
};
59-
60-
fetchZigArtifact = { name, url, hash }: let
61-
parts = splitString "://" url;
62-
proto = elemAt parts 0;
63-
path = elemAt parts 1;
64-
fetcher = {
65-
"git+http" = fetchGitZig { inherit name hash; url = "http://''${path}"; };
66-
"git+https" = fetchGitZig { inherit name hash; url = "https://''${path}"; };
67-
http = fetchZig { inherit name hash; url = "http://''${path}"; };
68-
https = fetchZig { inherit name hash; url = "https://''${path}"; };
67+
fetchGitZig =
68+
{
69+
name,
70+
url,
71+
hash,
72+
}:
73+
let
74+
parts = splitString "#" url;
75+
url_base = elemAt parts 0;
76+
url_without_query = elemAt (splitString "?" url_base) 0;
77+
rev_base = elemAt parts 1;
78+
rev = if match "^[a-fA-F0-9]{40}$" rev_base != null then rev_base else "refs/heads/''${rev_base}";
79+
in
80+
fetchgit {
81+
inherit name rev hash;
82+
url = url_without_query;
83+
deepClone = false;
6984
};
70-
in fetcher.''${proto};
71-
in linkFarm name [
85+
86+
fetchZigArtifact =
87+
{
88+
name,
89+
url,
90+
hash,
91+
}:
92+
let
93+
parts = splitString "://" url;
94+
proto = elemAt parts 0;
95+
path = elemAt parts 1;
96+
fetcher = {
97+
"git+http" = fetchGitZig {
98+
inherit name hash;
99+
url = "http://''${path}";
100+
};
101+
"git+https" = fetchGitZig {
102+
inherit name hash;
103+
url = "https://''${path}";
104+
};
105+
http = fetchZig {
106+
inherit name hash;
107+
url = "http://''${path}";
108+
};
109+
https = fetchZig {
110+
inherit name hash;
111+
url = "https://''${path}";
112+
};
113+
};
114+
in
115+
fetcher.''${proto};
116+
in
117+
linkFarm name [
72118
EOF
73119
74120
while {
@@ -88,6 +134,6 @@ writeShellApplication {
88134
}
89135
EOF
90136
done < <(jq -r 'to_entries | .[] | .key, .value.name, .value.url, .value.hash' "$path")
91-
printf ']'
137+
printf ']\n'
92138
'';
93139
}

0 commit comments

Comments
 (0)