···11+/*
22+This file is provided under the MIT licence:
33+44+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:
55+66+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
77+88+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.
99+*/
1010+# Generated by npins. Do not modify; will be overwritten regularly
1111+let
1212+ # Backwards-compatibly make something that previously didn't take any arguments take some
1313+ # The function must return an attrset, and will unfortunately be eagerly evaluated
1414+ # Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments
1515+ mkFunctor = fn: let
1616+ e = builtins.tryEval (fn {});
1717+ in
1818+ (
1919+ if e.success
2020+ then e.value
2121+ else {error = fn {};}
2222+ )
2323+ // {__functor = _self: fn;};
2424+2525+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
2626+ range = first: last:
2727+ if first > last
2828+ then []
2929+ else builtins.genList (n: first + n) (last - first + 1);
3030+3131+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
3232+ stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
3333+3434+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
3535+ stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
3636+ concatStrings = builtins.concatStringsSep "";
3737+3838+ # If the environment variable NPINS_OVERRIDE_${name} is set, then use
3939+ # the path directly as opposed to the fetched source.
4040+ # (Taken from Niv for compatibility)
4141+ mayOverride = name: path: let
4242+ envVarName = "NPINS_OVERRIDE_${saneName}";
4343+ saneName = stringAsChars (c:
4444+ if (builtins.match "[a-zA-Z0-9]" c) == null
4545+ then "_"
4646+ else c)
4747+ name;
4848+ ersatz = builtins.getEnv envVarName;
4949+ in
5050+ if ersatz == ""
5151+ then path
5252+ else
5353+ # this turns the string into an actual Nix path (for both absolute and
5454+ # relative paths)
5555+ builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
5656+ if builtins.substring 0 1 ersatz == "/"
5757+ then /. + ersatz
5858+ else /. + builtins.getEnv "PWD" + "/${ersatz}"
5959+ );
6060+6161+ mkSource = name: spec: {pkgs ? null}:
6262+ assert spec ? type; let
6363+ # Unify across builtin and pkgs fetchers.
6464+ # `fetchGit` requires a wrapper because of slight API differences.
6565+ fetchers =
6666+ if pkgs == null
6767+ then {
6868+ inherit (builtins) fetchTarball fetchurl;
6969+ # For some fucking reason, fetchGit has a different signature than the other builtin fetchers …
7070+ fetchGit = args: (builtins.fetchGit args).outPath;
7171+ }
7272+ else {
7373+ fetchTarball = {
7474+ url,
7575+ sha256,
7676+ }:
7777+ pkgs.fetchzip {
7878+ inherit url sha256;
7979+ extension = "tar";
8080+ };
8181+ inherit (pkgs) fetchurl;
8282+ fetchGit = {
8383+ url,
8484+ submodules,
8585+ rev,
8686+ name,
8787+ narHash,
8888+ }:
8989+ pkgs.fetchgit {
9090+ inherit url rev name;
9191+ fetchSubmodules = submodules;
9292+ hash = narHash;
9393+ };
9494+ };
9595+9696+ # Dispatch to the correct code path based on the type
9797+ path =
9898+ if spec.type == "Git"
9999+ then mkGitSource fetchers spec
100100+ else if spec.type == "GitRelease"
101101+ then mkGitSource fetchers spec
102102+ else if spec.type == "PyPi"
103103+ then mkPyPiSource fetchers spec
104104+ else if spec.type == "Channel"
105105+ then mkChannelSource fetchers spec
106106+ else if spec.type == "Tarball"
107107+ then mkTarballSource fetchers spec
108108+ else if spec.type == "Container"
109109+ then mkContainerSource pkgs spec
110110+ else builtins.throw "Unknown source type ${spec.type}";
111111+ in
112112+ spec // {outPath = mayOverride name path;};
113113+114114+ mkGitSource = {
115115+ fetchTarball,
116116+ fetchGit,
117117+ ...
118118+ }: {
119119+ repository,
120120+ revision,
121121+ url ? null,
122122+ submodules,
123123+ hash,
124124+ ...
125125+ }:
126126+ assert repository ? type;
127127+ # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
128128+ # In the latter case, there we will always be an url to the tarball
129129+ if url != null && !submodules
130130+ then
131131+ fetchTarball {
132132+ inherit url;
133133+ sha256 = hash;
134134+ }
135135+ else let
136136+ url =
137137+ if repository.type == "Git"
138138+ then repository.url
139139+ else if repository.type == "GitHub"
140140+ then "https://github.com/${repository.owner}/${repository.repo}.git"
141141+ else if repository.type == "GitLab"
142142+ then "${repository.server}/${repository.repo_path}.git"
143143+ else if repository.type == "Forgejo"
144144+ then "${repository.server}/${repository.owner}/${repository.repo}.git"
145145+ else throw "Unrecognized repository type ${repository.type}";
146146+ urlToName = url: rev: let
147147+ matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
148148+149149+ short = builtins.substring 0 7 rev;
150150+151151+ appendShort =
152152+ if (builtins.match "[a-f0-9]*" rev) != null
153153+ then "-${short}"
154154+ else "";
155155+ in "${
156156+ if matched == null
157157+ then "source"
158158+ else builtins.head matched
159159+ }${appendShort}";
160160+ name = urlToName url revision;
161161+ in
162162+ fetchGit {
163163+ rev = revision;
164164+ narHash = hash;
165165+166166+ inherit name submodules url;
167167+ };
168168+169169+ mkPyPiSource = {fetchurl, ...}: {
170170+ url,
171171+ hash,
172172+ ...
173173+ }:
174174+ fetchurl {
175175+ inherit url;
176176+ sha256 = hash;
177177+ };
178178+179179+ mkChannelSource = {fetchTarball, ...}: {
180180+ url,
181181+ hash,
182182+ ...
183183+ }:
184184+ fetchTarball {
185185+ inherit url;
186186+ sha256 = hash;
187187+ };
188188+189189+ mkTarballSource = {fetchTarball, ...}: {
190190+ url,
191191+ locked_url ? url,
192192+ hash,
193193+ ...
194194+ }:
195195+ fetchTarball {
196196+ url = locked_url;
197197+ sha256 = hash;
198198+ };
199199+200200+ mkContainerSource = pkgs: {
201201+ image_name,
202202+ image_tag,
203203+ image_digest,
204204+ ...
205205+ }:
206206+ if pkgs == null
207207+ then builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers"
208208+ else
209209+ pkgs.dockerTools.pullImage {
210210+ imageName = image_name;
211211+ imageDigest = image_digest;
212212+ finalImageTag = image_tag;
213213+ };
214214+in
215215+ mkFunctor (
216216+ {input ? ./sources.json}: let
217217+ data =
218218+ if builtins.isPath input
219219+ then
220220+ # while `readFile` will throw an error anyways if the path doesn't exist,
221221+ # we still need to check beforehand because *our* error can be caught but not the one from the builtin
222222+ # *piegames sighs*
223223+ if builtins.pathExists input
224224+ then builtins.fromJSON (builtins.readFile input)
225225+ else throw "Input path ${toString input} does not exist"
226226+ else if builtins.isAttrs input
227227+ then input
228228+ else throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset";
229229+ version = data.version;
230230+ in
231231+ if version == 7
232232+ then builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins
233233+ else throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
234234+ )