Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
content-address.hh
Go to the documentation of this file.
1#pragma once
3
4#include <variant>
5#include "nix/util/hash.hh"
6#include "nix/store/path.hh"
10
11namespace nix {
12
13/*
14 * Content addressing method
15 */
16
21std::string_view makeFileIngestionPrefix(FileIngestionMethod m);
22
32{
33 enum struct Raw {
42
52
63
72 Text,
73 };
74
75 Raw raw;
76
77 bool operator==(const ContentAddressMethod &) const = default;
78 auto operator<=>(const ContentAddressMethod &) const = default;
79
81
87 static ContentAddressMethod parse(std::string_view rawCaMethod);
88
94 std::string_view render() const;
95
105 static ContentAddressMethod parsePrefix(std::string_view & m);
106
112 std::string_view renderPrefix() const;
113
117 static std::pair<ContentAddressMethod, HashAlgorithm> parseWithAlgo(std::string_view rawCaMethod);
118
125 std::string renderWithAlgo(HashAlgorithm ha) const;
126
134
143};
144
145/*
146 * Mini content address
147 */
148
162{
167
172
173 bool operator==(const ContentAddress &) const = default;
174 auto operator<=>(const ContentAddress &) const = default;
175
181 std::string render() const;
182
183 static ContentAddress parse(std::string_view rawCa);
184
185 static std::optional<ContentAddress> parseOpt(std::string_view rawCaOpt);
186
187 std::string printMethodAlgo() const;
188};
189
194std::string renderContentAddress(std::optional<ContentAddress> ca);
195
196/*
197 * Full content address
198 *
199 * See the schema for store paths in store-api.cc
200 */
201
209{
213 StorePathSet others;
214
218 bool self = false;
219
224 bool empty() const;
225
230 size_t size() const;
231
232 bool operator==(const StoreReferences &) const = default;
233 // TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
234 // auto operator <=>(const StoreReferences &) const = default;
235};
236
237// This matches the additional info that we need for makeTextPath
239{
244
249 StorePathSet references;
250
251 bool operator==(const TextInfo &) const = default;
252 // TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
253 // auto operator <=>(const TextInfo &) const = default;
254};
255
257{
262
267
272
273 bool operator==(const FixedOutputInfo &) const = default;
274 // TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
275 // auto operator <=>(const FixedOutputInfo &) const = default;
276};
277
284{
285 typedef std::variant<TextInfo, FixedOutputInfo> Raw;
286
287 Raw raw;
288
289 bool operator==(const ContentAddressWithReferences &) const = default;
290 // TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
291 // auto operator <=>(const ContentAddressWithReferences &) const = default;
292
293 MAKE_WRAPPER_CONSTRUCTOR(ContentAddressWithReferences);
294
300
315
316 ContentAddressMethod getMethod() const;
317
318 Hash getHash() const;
319};
320
321template<>
322struct json_avoids_null<ContentAddressMethod> : std::true_type
323{};
324
325template<>
326struct json_avoids_null<ContentAddress> : std::true_type
327{};
328
329} // namespace nix
330
332JSON_IMPL(nix::ContentAddress)
FileSerialisationMethod
Definition file-content-address.hh:20
@ Flat
Definition file-content-address.hh:27
@ NixArchive
Definition file-content-address.hh:36
FileIngestionMethod
Definition file-content-address.hh:96
@ Git
Definition file-content-address.hh:121
std::string render(bool withParams=true) const
Definition content-address.hh:32
Raw
Definition content-address.hh:33
static std::pair< ContentAddressMethod, HashAlgorithm > parseWithAlgo(std::string_view rawCaMethod)
Definition content-address.cc:218
static ContentAddressMethod parsePrefix(std::string_view &m)
Definition content-address.cc:84
static ContentAddressMethod parse(std::string_view rawCaMethod)
Definition content-address.cc:62
std::string renderWithAlgo(HashAlgorithm ha) const
Definition content-address.cc:116
FileIngestionMethod getFileIngestionMethod() const
Definition content-address.cc:121
std::string_view renderPrefix() const
Definition content-address.cc:70
FileSerialisationMethod getFileSerialisationMethod() const
Definition content-address.cc:137
Definition content-address.hh:284
static ContentAddressWithReferences fromParts(ContentAddressMethod method, Hash hash, StoreReferences refs)
Definition content-address.cc:273
static ContentAddressWithReferences withoutRefs(const ContentAddress &) noexcept
Definition content-address.cc:251
Definition content-address.hh:162
Hash hash
Definition content-address.hh:171
ContentAddressMethod method
Definition content-address.hh:166
std::string render() const
Definition content-address.cc:151
Definition content-address.hh:257
FileIngestionMethod method
Definition content-address.hh:261
StoreReferences references
Definition content-address.hh:271
Hash hash
Definition content-address.hh:266
Definition hash.hh:58
Definition content-address.hh:209
bool empty() const
Definition content-address.cc:241
StorePathSet others
Definition content-address.hh:213
bool self
Definition content-address.hh:218
size_t size() const
Definition content-address.cc:246
Definition content-address.hh:239
Hash hash
Definition content-address.hh:243
StorePathSet references
Definition content-address.hh:249
#define MAKE_WRAPPER_CONSTRUCTOR(CLASS_NAME)
Definition variant-wrapper.hh:49