Link aggregation and post comments on ATProto!
1/*
2 This file is provided under the MIT licence:
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
6 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
8 THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9*/
10# Generated by npins. Do not modify; will be overwritten regularly
11let
12 # Backwards-compatibly make something that previously didn't take any arguments take some
13 # The function must return an attrset, and will unfortunately be eagerly evaluated
14 # Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments
15 mkFunctor =
16 fn:
17 let
18 e = (builtins.tryEval (fn { }));
19 in
20 (if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; };
21
22 # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
23 range =
24 first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
25
26 # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
27 stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
28
29 # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
30 stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
31 concatStrings = builtins.concatStringsSep "";
32
33 # If the environment variable NPINS_OVERRIDE_${name} is set, then use
34 # the path directly as opposed to the fetched source.
35 # (Taken from Niv for compatibility)
36 mayOverride =
37 name: path:
38 let
39 envVarName = "NPINS_OVERRIDE_${saneName}";
40 saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
41 ersatz = builtins.getEnv envVarName;
42 in
43 if ersatz == "" then
44 path
45 else
46 # this turns the string into an actual Nix path (for both absolute and
47 # relative paths)
48 builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
49 if builtins.substring 0 1 ersatz == "/" then
50 /. + ersatz
51 else
52 /. + builtins.getEnv "PWD" + "/${ersatz}"
53 );
54
55 mkSource =
56 name: spec:
57 {
58 pkgs ? null,
59 }:
60 assert spec ? type;
61 let
62 # Unify across builtin and pkgs fetchers.
63 # `fetchGit` requires a wrapper because of slight API differences.
64 fetchers =
65 if pkgs == null then
66 {
67 inherit (builtins) fetchTarball fetchurl;
68 # For some fucking reason, fetchGit has a different signature than the other builtin fetchers …
69 fetchGit = args: (builtins.fetchGit args).outPath;
70 }
71 else
72 {
73 fetchTarball =
74 {
75 url,
76 sha256,
77 }:
78 pkgs.fetchzip {
79 inherit url sha256;
80 extension = "tar";
81 };
82 inherit (pkgs) fetchurl;
83 fetchGit =
84 {
85 url,
86 submodules,
87 rev,
88 name,
89 narHash,
90 }:
91 pkgs.fetchgit {
92 inherit url rev name;
93 fetchSubmodules = submodules;
94 hash = narHash;
95 };
96 };
97
98 # Dispatch to the correct code path based on the type
99 path =
100 if spec.type == "Git" then
101 mkGitSource fetchers spec
102 else if spec.type == "GitRelease" then
103 mkGitSource fetchers spec
104 else if spec.type == "PyPi" then
105 mkPyPiSource fetchers spec
106 else if spec.type == "Channel" then
107 mkChannelSource fetchers spec
108 else if spec.type == "Tarball" then
109 mkTarballSource fetchers spec
110 else
111 builtins.throw "Unknown source type ${spec.type}";
112 in
113 spec // { outPath = mayOverride name path; };
114
115 mkGitSource =
116 { fetchTarball, fetchGit, ... }:
117 {
118 repository,
119 revision,
120 url ? null,
121 submodules,
122 hash,
123 ...
124 }:
125 assert repository ? type;
126 # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
127 # In the latter case, there we will always be an url to the tarball
128 if url != null && !submodules then
129 fetchTarball {
130 inherit url;
131 sha256 = hash;
132 }
133 else
134 let
135 url =
136 if repository.type == "Git" then
137 repository.url
138 else if repository.type == "GitHub" then
139 "https://github.com/${repository.owner}/${repository.repo}.git"
140 else if repository.type == "GitLab" then
141 "${repository.server}/${repository.repo_path}.git"
142 else
143 throw "Unrecognized repository type ${repository.type}";
144 urlToName =
145 url: rev:
146 let
147 matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
148
149 short = builtins.substring 0 7 rev;
150
151 appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
152 in
153 "${if matched == null then "source" else builtins.head matched}${appendShort}";
154 name = urlToName url revision;
155 in
156 fetchGit {
157 rev = revision;
158 narHash = hash;
159
160 inherit name submodules url;
161 };
162
163 mkPyPiSource =
164 { fetchurl, ... }:
165 { url, hash, ... }:
166 fetchurl {
167 inherit url;
168 sha256 = hash;
169 };
170
171 mkChannelSource =
172 { fetchTarball, ... }:
173 { url, hash, ... }:
174 fetchTarball {
175 inherit url;
176 sha256 = hash;
177 };
178
179 mkTarballSource =
180 { fetchTarball, ... }:
181 {
182 url,
183 locked_url ? url,
184 hash,
185 ...
186 }:
187 fetchTarball {
188 url = locked_url;
189 sha256 = hash;
190 };
191in
192mkFunctor (
193 {
194 input ? ./sources.json,
195 }:
196 let
197 data =
198 if builtins.isPath input then
199 # while `readFile` will throw an error anyways if the path doesn't exist,
200 # we still need to check beforehand because *our* error can be caught but not the one from the builtin
201 # *piegames sighs*
202 if builtins.pathExists input then
203 builtins.fromJSON (builtins.readFile input)
204 else
205 throw "Input path ${toString input} does not exist"
206 else if builtins.isAttrs input then
207 input
208 else
209 throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset";
210 version = data.version;
211 in
212 if version == 6 then
213 builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins
214 else
215 throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
216)