99*/
1010# Generated by npins. Do not modify; will be overwritten regularly
1111let
12- data = builtins . fromJSON ( builtins . readFile ./sources.json ) ;
13- version = data . version ;
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 ; } ;
1421
1522 # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
1623 range =
2128
2229 # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
2330 stringAsChars = f : s : concatStrings ( map f ( stringToCharacters s ) ) ;
24- concatMapStrings = f : list : concatStrings ( map f list ) ;
2531 concatStrings = builtins . concatStringsSep "" ;
2632
2733 # If the environment variable NPINS_OVERRIDE_${name} is set, then use
4854
4955 mkSource =
5056 name : spec :
57+ {
58+ pkgs ? null ,
59+ } :
5160 assert spec ? type ;
5261 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
5399 path =
54100 if spec . type == "Git" then
55- mkGitSource spec
101+ mkGitSource fetchers spec
56102 else if spec . type == "GitRelease" then
57- mkGitSource spec
103+ mkGitSource fetchers spec
58104 else if spec . type == "PyPi" then
59- mkPyPiSource spec
105+ mkPyPiSource fetchers spec
60106 else if spec . type == "Channel" then
61- mkChannelSource spec
107+ mkChannelSource fetchers spec
62108 else if spec . type == "Tarball" then
63- mkTarballSource spec
109+ mkTarballSource fetchers spec
110+ else if spec . type == "Container" then
111+ mkContainerSource pkgs spec
64112 else
65113 builtins . throw "Unknown source type ${ spec . type } " ;
66114 in
67115 spec // { outPath = mayOverride name path ; } ;
68116
69117 mkGitSource =
118+ {
119+ fetchTarball ,
120+ fetchGit ,
121+ ...
122+ } :
70123 {
71124 repository ,
72125 revision ,
73126 url ? null ,
74127 submodules ,
75128 hash ,
76- branch ? null ,
77129 ...
78130 } :
79131 assert repository ? type ;
80132 # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
81133 # In the latter case, there we will always be an url to the tarball
82134 if url != null && ! submodules then
83- builtins . fetchTarball {
135+ fetchTarball {
84136 inherit url ;
85137 sha256 = hash ;
86138 }
@@ -107,40 +159,89 @@ let
107159 "${ if matched == null then "source" else builtins . head matched } ${ appendShort } " ;
108160 name = urlToName url revision ;
109161 in
110- builtins . fetchGit {
162+ fetchGit {
111163 rev = revision ;
112164 narHash = hash ;
113165
114166 inherit name submodules url ;
115167 } ;
116168
117169 mkPyPiSource =
118- { url , hash , ... } :
119- builtins . fetchurl {
170+ { fetchurl , ... } :
171+ {
172+ url ,
173+ hash ,
174+ ...
175+ } :
176+ fetchurl {
120177 inherit url ;
121178 sha256 = hash ;
122179 } ;
123180
124181 mkChannelSource =
125- { url , hash , ... } :
126- builtins . fetchTarball {
182+ { fetchTarball , ... } :
183+ {
184+ url ,
185+ hash ,
186+ ...
187+ } :
188+ fetchTarball {
127189 inherit url ;
128190 sha256 = hash ;
129191 } ;
130192
131193 mkTarballSource =
194+ { fetchTarball , ... } :
132195 {
133196 url ,
134197 locked_url ? url ,
135198 hash ,
136199 ...
137200 } :
138- builtins . fetchTarball {
201+ fetchTarball {
139202 url = locked_url ;
140203 sha256 = hash ;
141204 } ;
205+
206+ mkContainerSource =
207+ pkgs :
208+ {
209+ image_name ,
210+ image_tag ,
211+ image_digest ,
212+ ...
213+ } :
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"
216+ else
217+ pkgs . dockerTools . pullImage {
218+ imageName = image_name ;
219+ imageDigest = image_digest ;
220+ finalImageTag = image_tag ;
221+ } ;
142222in
143- if version == 6 then
144- builtins . mapAttrs mkSource data . pins
145- else
146- throw "Unsupported format version ${ toString version } in sources.json. Try running `npins upgrade`"
223+ mkFunctor (
224+ {
225+ input ? ./sources.json ,
226+ } :
227+ let
228+ data =
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
232+ # *piegames sighs*
233+ if builtins . pathExists input then
234+ builtins . fromJSON ( builtins . readFile input )
235+ else
236+ throw "Input path ${ toString input } does not exist"
237+ else if builtins . isAttrs input then
238+ input
239+ else
240+ throw "Unsupported input type ${ builtins . typeOf input } , must be a path or an attrset" ;
241+ version = data . version ;
242+ in
243+ if version == 7 then
244+ builtins . mapAttrs ( name : spec : mkFunctor ( mkSource name spec ) ) data . pins
245+ else
246+ throw "Unsupported format version ${ toString version } in sources.json. Try running `npins upgrade`"
247+ )
0 commit comments