···
2
+
This file is provided under the MIT licence:
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:
6
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
10
+
# Generated by npins. Do not modify; will be overwritten regularly
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
18
+
e = builtins.tryEval (fn { });
20
+
(if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; };
22
+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
24
+
first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
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));
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 "";
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)
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;
43
+
if ersatz == "" then
46
+
# this turns the string into an actual Nix path (for both absolute and
48
+
builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
49
+
if builtins.substring 0 1 ersatz == "/" then
52
+
/. + builtins.getEnv "PWD" + "/${ersatz}"
62
+
# Unify across builtin and pkgs fetchers.
63
+
# `fetchGit` requires a wrapper because of slight API differences.
65
+
if pkgs == null then
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;
82
+
inherit (pkgs) fetchurl;
92
+
inherit url rev name;
93
+
fetchSubmodules = submodules;
98
+
# Dispatch to the correct code path based on the type
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 if spec.type == "Container" then
111
+
mkContainerSource pkgs spec
113
+
builtins.throw "Unknown source type ${spec.type}";
115
+
spec // { outPath = mayOverride name path; };
131
+
assert repository ? type;
132
+
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
133
+
# In the latter case, there we will always be an url to the tarball
134
+
if url != null && !submodules then
142
+
if repository.type == "Git" then
144
+
else if repository.type == "GitHub" then
145
+
"https://github.com/${repository.owner}/${repository.repo}.git"
146
+
else if repository.type == "GitLab" then
147
+
"${repository.server}/${repository.repo_path}.git"
149
+
throw "Unrecognized repository type ${repository.type}";
153
+
matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
155
+
short = builtins.substring 0 7 rev;
157
+
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
159
+
"${if matched == null then "source" else builtins.head matched}${appendShort}";
160
+
name = urlToName url revision;
166
+
inherit name submodules url;
182
+
{ fetchTarball, ... }:
194
+
{ fetchTarball, ... }:
206
+
mkContainerSource =
214
+
if pkgs == null then
215
+
builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers"
217
+
pkgs.dockerTools.pullImage {
218
+
imageName = image_name;
219
+
imageDigest = image_digest;
220
+
finalImageTag = image_tag;
225
+
input ? ./sources.json,
229
+
if builtins.isPath input then
230
+
# while `readFile` will throw an error anyways if the path doesn't exist,
231
+
# we still need to check beforehand because *our* error can be caught but not the one from the builtin
233
+
if builtins.pathExists input then
234
+
builtins.fromJSON (builtins.readFile input)
236
+
throw "Input path ${toString input} does not exist"
237
+
else if builtins.isAttrs input then
240
+
throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset";
241
+
version = data.version;
243
+
if version == 7 then
244
+
builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins
246
+
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"