this repo has no description
1# this is really just a fork of fetchFromGitHub, but with a few changes due to
2# incompatibilities. furthermore, there is no such concept of private in
3# atproto, so all the private stuff has been removed.
4
5{
6 lib,
7 repoRevToNameMaybe,
8 fetchgit,
9 fetchzip,
10}:
11
12let
13
14 useFetchGitArgsDefault = {
15 deepClone = false;
16 fetchSubmodules = false; # This differs from fetchgit's default
17 fetchLFS = false;
18 forceFetchGit = false;
19 leaveDotGit = null;
20 postCheckout = "";
21 rootDir = "";
22 sparseCheckout = null;
23 };
24 useFetchGitArgsDefaultNullable = {
25 leaveDotGit = false;
26 sparseCheckout = [ ];
27 };
28 useFetchGitargsDefaultNonNull = useFetchGitArgsDefault // useFetchGitArgsDefaultNullable;
29 excludeUseFetchGitArgNames = [
30 "forceFetchGit"
31 ];
32
33 faUseFetchGit = lib.mapAttrs (_: _: true) useFetchGitArgsDefault;
34
35 adjustFunctionArgs = f: lib.setFunctionArgs f (faUseFetchGit // lib.functionArgs f);
36
37 decorate = f: lib.makeOverridable (adjustFunctionArgs f);
38
39in
40
41decorate (
42 {
43 domain ? "tangled.org",
44 did,
45 rev ? null,
46 tag ? null,
47
48 # TODO: add back when doing FP
49 # name ? repoRevToNameMaybe did (lib.revOrTag rev tag) "tangled",
50
51 passthru ? { },
52 meta ? { },
53 ...
54 }@args:
55
56 assert lib.assertMsg (lib.xor (tag != null) (
57 rev != null
58 )) "fetchFromTangled requires one of either `rev` or `tag` to be provided (not both).";
59
60 let
61
62 useFetchGit =
63 lib.mapAttrs (
64 name: nonNullDefault:
65 if args ? ${name} && (useFetchGitArgsDefaultNullable ? ${name} -> args.${name} != null) then
66 args.${name}
67 else
68 nonNullDefault
69 ) useFetchGitargsDefaultNonNull != useFetchGitargsDefaultNonNull;
70
71 useFetchGitArgsWDPassing = lib.overrideExisting (removeAttrs useFetchGitArgsDefault excludeUseFetchGitArgNames) args;
72
73 position = (
74 if args.meta.description or null != null then
75 builtins.unsafeGetAttrPos "description" args.meta
76 else if tag != null then
77 builtins.unsafeGetAttrPos "tag" args
78 else
79 builtins.unsafeGetAttrPos "rev" args
80 );
81
82 baseUrl = "https://${domain}/${did}";
83
84 newMeta =
85 meta
86 // {
87 homepage = meta.homepage or baseUrl;
88 }
89 // lib.optionalAttrs (position != null) {
90 # to indicate where derivation originates, similar to make-derivation.nix's mkDerivation
91 position = "${position.file}:${toString position.line}";
92 };
93
94 passthruAttrs = removeAttrs args (
95 [
96 "domain"
97 "did"
98 "tag"
99 "rev"
100 "fetchSubmodules"
101 "forceFetchGit"
102 ]
103 ++ (if useFetchGit then excludeUseFetchGitArgNames else lib.attrNames faUseFetchGit)
104 );
105
106 # We prefer fetchzip in cases we don't need submodules as the hash
107 # is more stable in that case.
108 fetcher =
109 if useFetchGit then
110 fetchgit
111 # fetchzip may not be overridable when using external tools, for example nix-prefetch
112 else if fetchzip ? override then
113 fetchzip.override { withUnzip = false; }
114 else
115 fetchzip;
116
117 fetcherArgs =
118 finalAttrs:
119 passthruAttrs
120 // (
121 if useFetchGit then
122 useFetchGitArgsWDPassing
123 // {
124 inherit tag rev;
125 url = baseUrl;
126 inherit passthru;
127 derivationArgs = {
128 inherit
129 domain
130 did
131 ;
132 };
133 }
134 else
135 let
136 revWithTag = finalAttrs.rev;
137 in
138 {
139 url = "${baseUrl}/archive/${revWithTag}?prefix=${did}";
140 extension = "tar.gz";
141
142 derivationArgs = {
143 inherit
144 domain
145 did
146 tag
147 ;
148 rev = fetchgit.getRevWithTag {
149 inherit (finalAttrs) tag;
150 rev = finalAttrs.revCustom;
151 };
152 revCustom = rev;
153 };
154
155 passthru = {
156 gitRepoUrl = baseUrl;
157 }
158 // passthru;
159 }
160 )
161 // {
162 name =
163 args.name
164 or (repoRevToNameMaybe finalAttrs.did (lib.revOrTag finalAttrs.revCustom finalAttrs.tag) "tangled");
165 meta = newMeta;
166 };
167 in
168
169 fetcher fetcherArgs
170)