···1+# this is really just a fork of fetchFromGitHub, but with a few changes due to
2+# incompatibilities, for example `tag` is removed and there is no such concept
3+# of private in atproto, so all the private stuff has been removed.
4+#
5+#
6+# as of the time of writing, `.git` suffixed urls do not resolve correctly
7+# either
8+#
9+# as of the time of writing too
10+# `https://tangled.sh/@rockorager.dev/lsr/archive/v1.0.0.tar.gz` resolves to
11+# `https://knot1.tangled.sh/did:plc:vk2bemsr3uxaw4fdzno3chsh/lsr/archive/v1.0.0.tar.gz.tar.gz`
12+# which is an invalid url.
13+14+{
15+ lib,
16+ repoRevToNameMaybe,
17+ fetchgit,
18+ fetchzip,
19+}:
2021lib.makeOverridable (
22 {
23 domain ? "tangled.sh",
24+ owner,
25+ repo,
26+ rev ? null,
27+ name ? repoRevToNameMaybe repo rev "tangled",
28+29+ # fetchgit stuff
30+ fetchSubmodules ? false,
31+ leaveDotGit ? false,
32+ deepClone ? false,
33+ forceFetchGit ? false,
34+ fetchLFS ? false,
35+ sparseCheckout ? [ ],
36+37+ meta ? { },
38 ...
39 }@args:
4041+ let
42+43+ position = (
44+ if args.meta.description or null != null then
45+ builtins.unsafeGetAttrPos "description" args.meta
46+ else
47+ builtins.unsafeGetAttrPos "rev" args
48+ );
49+50+ baseUrl = "https://${domain}/${owner}/${repo}";
51+52+ newMeta =
53+ meta
54+ // {
55+ homepage = meta.homepage or baseUrl;
56+ }
57+ // lib.optionalAttrs (position != null) {
58+ # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation
59+ position = "${position.file}:${toString position.line}";
60+ };
61+62+ passthruAttrs = removeAttrs args [
63+ "domain"
64+ "owner"
65+ "repo"
66+ "rev"
67+ "fetchSubmodules"
68+ "forceFetchGit"
69+ ];
70+71+ useFetchGit =
72+ fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || fetchLFS || (sparseCheckout != [ ]);
73+74+ # We prefer fetchzip in cases we don't need submodules as the hash
75+ # is more stable in that case.
76+ fetcher =
77+ if useFetchGit then
78+ fetchgit
79+ # fetchzip may not be overridable when using external tools, for example nix-prefetch
80+ else if fetchzip ? override then
81+ fetchzip.override { withUnzip = false; }
82+ else
83+ fetchzip;
84+85+ fetcherArgs =
86+ (
87+ if useFetchGit then
88+ {
89+ inherit
90+ rev
91+ deepClone
92+ fetchSubmodules
93+ sparseCheckout
94+ fetchLFS
95+ leaveDotGit
96+ ;
97+ url = baseUrl;
98+ }
99+ else
100+ {
101+ url = "${baseUrl}/archive/${rev}";
102+ extension = "tar.gz";
103+104+ passthru = {
105+ gitRepoUrl = baseUrl;
106+ };
107+ }
108+ )
109+ // passthruAttrs
110+ // {
111+ inherit name;
112+ };
113+ in
114+115+ fetcher fetcherArgs
116+ // {
117+ meta = newMeta;
118+ inherit owner repo rev;
119+ }
120)