Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
descriptor.hh
Go to the documentation of this file.
1/* ========================================================================== *
2 *
3 * @file flox/resolver/descriptor.hh
4 *
5 * @brief A set of user inputs used to set input preferences and query
6 * parameters during resolution.
7 *
8 *
9 * -------------------------------------------------------------------------- */
10
11#pragma once
12
13#include <functional>
14#include <string>
15#include <vector>
16
17#include <nlohmann/json.hpp>
18
19#include "flox/core/types.hh"
21#include "flox/registry.hh"
22
23
24/* -------------------------------------------------------------------------- */
25
26namespace flox::resolver {
27
28/* -------------------------------------------------------------------------- */
29
31using GroupName = std::string;
32
33
34/* -------------------------------------------------------------------------- */
35
43{
44
45public:
46
48 static const auto inputSigil = ':';
49
51 static const auto versionSigil = '@';
52
56 static const auto exactVersionSigil = '=';
57
62 std::optional<std::string> name;
63
72 std::optional<std::string> version;
73
75 using Path = std::variant<std::string, flox::AttrPath>;
77 std::optional<Path> path;
78
88 using AbsPath = std::variant<std::string, AttrPathGlob>;
90 std::optional<AbsPath> absPath;
91
93 std::optional<std::vector<System>> systems;
94
96 std::optional<bool> optional;
97
98 // TODO: Not implemented.
100 std::optional<GroupName> packageGroup;
101
102 // TODO: Not implemented.
104 std::optional<std::variant<std::string, nix::fetchers::Attrs>>
106
107
115 std::optional<unsigned> priority;
116
124 void
125 check( const std::string iid = "*" ) const;
126
128 void
129 clear();
130
131 ManifestDescriptorRaw() = default;
132
133 explicit ManifestDescriptorRaw( const std::string_view & descriptor );
134
135}; /* End struct `ManifestDescriptorRaw' */
136
137
138/* -------------------------------------------------------------------------- */
139
140// TODO: support `packageRepository' field
143void
144from_json( const nlohmann::json & jfrom, ManifestDescriptorRaw & descriptor );
145
150void
151to_json( nlohmann::json & jto, const ManifestDescriptorRaw & descriptor );
152
153
154/* -------------------------------------------------------------------------- */
155
164 "error parsing manifest descriptor" )
168/* -------------------------------------------------------------------------- */
169
170
175std::optional<std::string>
176validatedSingleAttr( const AttrPathGlob & attrs );
177
184bool
185globInAttrName( const AttrPathGlob & attrs );
186
192std::vector<std::string>
193validatedRelativePath( const AttrPathGlob & attrs,
194 const std::vector<std::string> & strings );
195
202validatedAbsolutePath( const AttrPathGlob & attrs );
203
208bool
209isAbsolutePath( const AttrPathGlob & attrs );
210
211/* -------------------------------------------------------------------------- */
212
221{
222
223public:
224
226 std::optional<std::string> name;
227
229 bool optional = false;
230
232 std::optional<GroupName> group;
233
235 std::optional<std::string> version;
236
238 std::optional<std::string> semver;
239
241 std::optional<Subtree> subtree;
242
244 std::optional<std::vector<System>> systems;
245
247 std::optional<flox::AttrPath> path;
248
250 std::optional<nix::FlakeRef> input;
251
259 unsigned priority = 5;
260
261
262 ManifestDescriptor() = default;
263
264 explicit ManifestDescriptor( const std::string_view & descriptor )
265 : ManifestDescriptor( ManifestDescriptorRaw( descriptor ) ) {};
266
267 explicit ManifestDescriptor( const ManifestDescriptorRaw & raw );
268
269 explicit ManifestDescriptor( std::string_view installID,
270 const ManifestDescriptorRaw & raw )
271 : ManifestDescriptor( raw )
272 {
273 if ( ! this->name.has_value() ) { this->name = installID; }
274 }
275
281 void
282 check() const;
283
285 void
286 clear();
287
297 pkgdb::PkgQueryArgs &
298 fillPkgQueryArgs( pkgdb::PkgQueryArgs & pqa ) const;
299
300
301}; /* End struct `ManifestDescriptor' */
302
303
304/* -------------------------------------------------------------------------- */
305
310void
311to_json( nlohmann::json & jto, const ManifestDescriptor & descriptor );
312
313/* -------------------------------------------------------------------------- */
314
324 "invalid manifest descriptor" )
328/* -------------------------------------------------------------------------- */
329
330} // namespace flox::resolver
331
332
333/* -------------------------------------------------------------------------- *
334 *
335 *
336 *
337 * ========================================================================== */
An exception thrown when parsing flox::resolver::ManifestDescriptorRaw from JSON.
An exception thrown when a package descriptor in a manifest is invalid.
std::string GroupName
A named group which a descriptor/package can be a member of.
Definition: descriptor.hh:31
#define FLOX_DEFINE_EXCEPTION(NAME, ERROR_CODE, CATEGORY_MSG)
Generate a class definition with an error code and category message.
Definition: exceptions.hh:206
@ EC_PARSE_MANIFEST_DESCRIPTOR_RAW
Definition: exceptions.hh:57
@ EC_INVALID_MANIFEST_DESCRIPTOR
Definition: exceptions.hh:39
std::vector< std::optional< std::string > > AttrPathGlob
An attribute path which may contain null members to represent globs.
Definition: types.hh:41
void from_json(const nlohmann::json &jfrom, RawPackage &pkg)
Convert a JSON object to a flox::RawPackage.
Definition: raw-package.cc:27
void to_json(nlohmann::json &jto, const FloxException &err)
Convert a flox::FloxException to a JSON object.
Definition: exceptions.cc:27
Interfaces for constructing complex ‘Packages’ queries.
A set of user inputs used to set input preferences during search and resolution.
A set of user defined requirements describing a package/dependency.
Definition: descriptor.hh:43
std::optional< std::vector< System > > systems
Definition: descriptor.hh:93
std::optional< std::variant< std::string, nix::fetchers::Attrs > > packageRepository
Definition: descriptor.hh:105
std::optional< std::string > version
Definition: descriptor.hh:72
void clear()
Reset to default/empty state.
Definition: descriptor.cc:46
std::variant< std::string, AttrPathGlob > AbsPath
A dot separated attribut path, or list representation. May contain null members to represent globs.
Definition: descriptor.hh:88
void check(const std::string iid="*") const
Ensure that a raw descriptor's fields are valid or throws an exception if the descriptor is invalid.
Definition: descriptor.cc:63
std::optional< GroupName > packageGroup
Definition: descriptor.hh:100
std::variant< std::string, flox::AttrPath > Path
A dot separated attribut path, or list representation.
Definition: descriptor.hh:75
std::optional< AbsPath > absPath
Definition: descriptor.hh:90
std::optional< bool > optional
Definition: descriptor.hh:96
std::optional< unsigned > priority
Definition: descriptor.hh:115
static const auto exactVersionSigil
Definition: descriptor.hh:56
static const auto versionSigil
Definition: descriptor.hh:51
std::optional< Path > path
Definition: descriptor.hh:77
std::optional< std::string > name
Definition: descriptor.hh:62
static const auto inputSigil
Definition: descriptor.hh:48
A set of user defined requirements describing a package/dependency.
Definition: descriptor.hh:221
std::optional< Subtree > subtree
Definition: descriptor.hh:241
std::optional< GroupName > group
Definition: descriptor.hh:232
std::optional< std::vector< System > > systems
Definition: descriptor.hh:244
std::optional< std::string > version
Definition: descriptor.hh:235
std::optional< std::string > name
Definition: descriptor.hh:226
std::optional< nix::FlakeRef > input
Definition: descriptor.hh:250
std::optional< flox::AttrPath > path
Definition: descriptor.hh:247
void check() const
Ensure that a descriptor has at least name, path, or absPath fields. Throws an exception if the descr...
std::optional< std::string > semver
Definition: descriptor.hh:238
Miscellaneous typedefs and aliases.