Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
fetchers.hh
Go to the documentation of this file.
1#pragma once
3
4#include "types.hh"
5#include "hash.hh"
6#include "canon-path.hh"
7#include "json-impls.hh"
8#include "attrs.hh"
9#include "url.hh"
10
11#include <memory>
12#include <nlohmann/json_fwd.hpp>
13
14#include "ref.hh"
15
16namespace nix { class Store; class StorePath; struct SourceAccessor; }
17
18namespace nix::fetchers {
19
20struct InputScheme;
21
22struct Settings;
23
31struct Input
32{
33 friend struct InputScheme;
34
35 const Settings * settings;
36
37 Input(const Settings & settings)
38 : settings{&settings}
39 { }
40
41 std::shared_ptr<InputScheme> scheme; // note: can be null
42 Attrs attrs;
43
47 mutable std::optional<std::optional<std::string>> cachedFingerprint;
48
49public:
55 static Input fromURL(
56 const Settings & settings,
57 const std::string & url, bool requireTree = true);
58
59 static Input fromURL(
60 const Settings & settings,
61 const ParsedURL & url, bool requireTree = true);
62
68 static Input fromAttrs(
69 const Settings & settings,
70 Attrs && attrs);
71
72 ParsedURL toURL() const;
73
74 std::string toURLString(const std::map<std::string, std::string> & extraQuery = {}) const;
75
76 std::string to_string() const;
77
78 Attrs toAttrs() const;
79
84 bool isDirect() const;
85
91 bool isLocked() const;
92
100 const Settings & settings) const;
101
106 std::optional<std::string> isRelative() const;
107
118 bool isFinal() const;
119
120 bool operator ==(const Input & other) const noexcept;
121
122 bool operator <(const Input & other) const
123 {
124 return attrs < other.attrs;
125 }
126
127 bool contains(const Input & other) const;
128
133 std::pair<StorePath, Input> fetchToStore(ref<Store> store) const;
134
146 static void checkLocks(Input specified, Input & result);
147
153 std::pair<ref<SourceAccessor>, Input> getAccessor(ref<Store> store) const;
154
155private:
156
157 std::pair<ref<SourceAccessor>, Input> getAccessorUnchecked(ref<Store> store) const;
158
159public:
160
161 Input applyOverrides(
162 std::optional<std::string> ref,
163 std::optional<Hash> rev) const;
164
165 void clone(const Path & destDir) const;
166
167 std::optional<std::filesystem::path> getSourcePath() const;
168
173 void putFile(
174 const CanonPath & path,
175 std::string_view contents,
176 std::optional<std::string> commitMsg) const;
177
178 std::string getName() const;
179
180 StorePath computeStorePath(Store & store) const;
181
182 // Convenience functions for common attributes.
183 std::string getType() const;
184 std::optional<Hash> getNarHash() const;
185 std::optional<std::string> getRef() const;
186 std::optional<Hash> getRev() const;
187 std::optional<uint64_t> getRevCount() const;
188 std::optional<time_t> getLastModified() const;
189
198 std::optional<std::string> getFingerprint(ref<Store> store) const;
199};
200
211{
212 virtual ~InputScheme()
213 { }
214
215 virtual std::optional<Input> inputFromURL(
216 const Settings & settings,
217 const ParsedURL & url, bool requireTree) const = 0;
218
219 virtual std::optional<Input> inputFromAttrs(
220 const Settings & settings,
221 const Attrs & attrs) const = 0;
222
230 virtual std::string_view schemeName() const = 0;
231
239 virtual StringSet allowedAttrs() const = 0;
240
241 virtual ParsedURL toURL(const Input & input) const;
242
243 virtual Input applyOverrides(
244 const Input & input,
245 std::optional<std::string> ref,
246 std::optional<Hash> rev) const;
247
248 virtual void clone(const Input & input, const Path & destDir) const;
249
250 virtual std::optional<std::filesystem::path> getSourcePath(const Input & input) const;
251
252 virtual void putFile(
253 const Input & input,
254 const CanonPath & path,
255 std::string_view contents,
256 std::optional<std::string> commitMsg) const;
257
258 virtual std::pair<ref<SourceAccessor>, Input> getAccessor(ref<Store> store, const Input & input) const = 0;
259
263 virtual std::optional<ExperimentalFeature> experimentalFeature() const;
264
265 virtual bool isDirect(const Input & input) const
266 { return true; }
267
268 virtual std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const
269 { return std::nullopt; }
270
271 virtual bool isLocked(const Input & input) const
272 { return false; }
273
274 virtual std::optional<std::string> isRelative(const Input & input) const
275 { return std::nullopt; }
276};
277
278void registerInputScheme(std::shared_ptr<InputScheme> && fetcher);
279
280nlohmann::json dumpRegisterInputSchemeInfo();
281
283{
284 std::string type = "ssh-ed25519";
285 std::string key;
286
287 auto operator <=>(const PublicKey &) const = default;
288};
289
290std::string publicKeys_to_string(const std::vector<PublicKey>&);
291
292}
293
294JSON_IMPL(fetchers::PublicKey)
std::map< std::string, Attr > Attrs
Definition attrs.hh:22
Definition canon-path.hh:41
Definition path.hh:27
Definition store-api.hh:169
Definition ref.hh:15
ChunkedVector< std::string, 8192 > store
Definition lexer.l:1011
std::optional< SourcePath > getSourcePath() const
Definition lexer.l:6577
virtual std::optional< time_t > getLastModified()
Definition lexer.l:4585
Definition url.hh:9
Definition source-accessor.hh:42
Definition fetchers.hh:211
virtual StringSet allowedAttrs() const =0
virtual std::string_view schemeName() const =0
virtual std::optional< ExperimentalFeature > experimentalFeature() const
Definition fetchers.cc:483
Definition fetchers.hh:32
bool isConsideredLocked(const Settings &settings) const
Definition fetchers.cc:158
bool isDirect() const
Definition fetchers.cc:148
std::optional< std::optional< std::string > > cachedFingerprint
Definition fetchers.hh:47
std::pair< ref< SourceAccessor >, Input > getAccessor(ref< Store > store) const
Definition fetchers.cc:288
bool isLocked() const
Definition fetchers.cc:153
std::optional< std::string > isRelative() const
Definition fetchers.cc:169
static Input fromURL(const Settings &settings, const std::string &url, bool requireTree=true)
Definition fetchers.cc:40
std::pair< StorePath, Input > fetchToStore(ref< Store > store) const
Definition fetchers.cc:195
static void checkLocks(Input specified, Input &result)
Definition fetchers.cc:229
void putFile(const CanonPath &path, std::string_view contents, std::optional< std::string > commitMsg) const
Definition fetchers.cc:367
bool isFinal() const
Definition fetchers.cc:164
std::optional< std::string > getFingerprint(ref< Store > store) const
Definition fetchers.cc:115
static Input fromAttrs(const Settings &settings, Attrs &&attrs)
Definition fetchers.cc:73
Definition fetchers.hh:283
Definition fetch-settings.hh:15
std::string Path
Definition types.hh:22