robin/ivy

my custom neovim config

git clone https://git.robinwobin.dev/robin/ivy

robinnix: use weavecd23569

main
8.4 KiB260 linesraw
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            # Frustratingly, due to flakes and `fetchTree`, `fetchGit`
69            # has a different signature than the other builtin
70            # fetchers
71            fetchGit = args: (builtins.fetchGit args).outPath;
72          }
73        else
74          {
75            fetchTarball =
76              {
77                url,
78                sha256,
79              }:
80              pkgs.fetchzip {
81                inherit url sha256;
82                extension = "tar";
83              };
84            inherit (pkgs) fetchurl;
85            fetchGit =
86              {
87                url,
88                submodules,
89                rev,
90                name,
91                narHash,
92              }:
93              pkgs.fetchgit {
94                inherit url rev name;
95                fetchSubmodules = submodules;
96                hash = narHash;
97              };
98          };
99
100      path =
101        if spec.type == "Git" then
102          mkGitSource fetchers spec
103        else if spec.type == "GitRelease" then
104          mkGitSource fetchers spec
105        else if spec.type == "PyPi" then
106          mkPyPiSource fetchers spec
107        else if spec.type == "Channel" then
108          mkChannelSource fetchers spec
109        else if spec.type == "Url" || spec.type == "MutableUrl" then
110          mkUrlSource fetchers spec
111        else if spec.type == "Container" then
112          mkContainerSource pkgs spec
113        else
114          builtins.throw "Unknown source type ${spec.type}";
115    in
116    spec // { outPath = mayOverride name path; };
117
118  mkGitSource =
119    {
120      fetchTarball,
121      fetchGit,
122      ...
123    }:
124    {
125      repository,
126      revision,
127      url ? null,
128      submodules,
129      hash,
130      ...
131    }:
132    assert repository ? type;
133    # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
134    # In the latter case, there we will always be an url to the tarball
135    if url != null && !submodules then
136      fetchTarball {
137        inherit url;
138        sha256 = hash;
139      }
140    else
141      let
142        url =
143          if repository.type == "Git" then
144            repository.url
145          else if repository.type == "GitHub" then
146            "https://github.com/${repository.owner}/${repository.repo}.git"
147          else if repository.type == "GitLab" then
148            "${repository.server}/${repository.repo_path}.git"
149          else if repository.type == "Forgejo" then
150            "${repository.server}/${repository.owner}/${repository.repo}.git"
151          else
152            throw "Unrecognized repository type ${repository.type}";
153        urlToName =
154          url: rev:
155          let
156            matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
157
158            short = builtins.substring 0 7 rev;
159
160            appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
161          in
162          "${if matched == null then "source" else builtins.head matched}${appendShort}";
163        name = urlToName url revision;
164      in
165      fetchGit {
166        rev = revision;
167        narHash = hash;
168
169        inherit name submodules url;
170      };
171
172  mkPyPiSource =
173    { fetchurl, ... }:
174    {
175      url,
176      hash,
177      ...
178    }:
179    fetchurl {
180      inherit url;
181      sha256 = hash;
182    };
183
184  mkChannelSource =
185    { fetchTarball, ... }:
186    {
187      url,
188      hash,
189      ...
190    }:
191    fetchTarball {
192      inherit url;
193      sha256 = hash;
194    };
195
196  mkUrlSource =
197    {
198      fetchTarball,
199      fetchurl,
200      ...
201    }:
202    {
203      url,
204      hash,
205      unpack,
206      ...
207    }:
208    (if unpack then fetchTarball else fetchurl) {
209      inherit url;
210      sha256 = hash;
211    };
212
213  mkContainerSource =
214    pkgs:
215    {
216      image_name,
217      image_tag,
218      image_digest,
219      hash,
220      ...
221    }@args:
222    if pkgs == null then
223      builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers"
224    else
225      pkgs.dockerTools.pullImage (
226        {
227          imageName = image_name;
228          imageDigest = image_digest;
229          finalImageTag = image_tag;
230          hash = hash;
231        }
232        // (if args.arch or null != null then { arch = args.arch; } else { })
233      );
234
235in
236mkFunctor (
237  {
238    input ? ./sources.json,
239  }:
240  let
241    data =
242      if builtins.isPath input then
243        # while `readFile` will throw an error anyways if the path doesn't exist,
244        # we still need to check beforehand because *our* error can be caught but not the one from the builtin
245        # See: <https://git.lix.systems/lix-project/lix/issues/1098>
246        if builtins.pathExists input then
247          builtins.fromJSON (builtins.readFile input)
248        else
249          throw "Input path ${toString input} does not exist"
250      else if builtins.isAttrs input then
251        input
252      else
253        throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset";
254    version = data.version;
255  in
256  if version == 8 then
257    builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins
258  else
259    throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
260)