Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
mixins.hh
Go to the documentation of this file.
1/* ========================================================================== *
2 *
3 * @file flox/resolver/mixins.hh
4 *
5 * @brief State blobs for flox commands.
6 *
7 *
8 * -------------------------------------------------------------------------- */
9
10#pragma once
11
12#include <filesystem>
13#include <optional>
14#include <string_view>
15
20
21
22/* -------------------------------------------------------------------------- */
23
24/* Forward Declarations */
25
26namespace argparse {
27
28class Argument;
29class ArgumentParser;
30
31} // namespace argparse
32
33
34/* -------------------------------------------------------------------------- */
35
36namespace flox::resolver {
37
38/* -------------------------------------------------------------------------- */
39
46FLOX_DEFINE_EXCEPTION( EnvironmentMixinException,
48 "error handling manifest or lockfile" )
52/* -------------------------------------------------------------------------- */
53
54
59class EnvironmentMixin
60{
61
62private:
63
64 /* All member variables are calculated lazily using `std::optional' and
65 * `get<MEMBER>' accessors.
66 * Even for internal access you should use the `get<MEMBER>' accessors to
67 * lazily initialize. */
68
69 /* ------------------------------ arguments ------------------------------- */
70
71
73 std::optional<std::filesystem::path> manifestPath;
74
75 /* ----------------------------- lazy fields ------------------------------ */
76
77
82 std::optional<GlobalManifest> globalManifest;
83
88 std::optional<ManifestRaw> manifestRaw;
89
94 std::optional<EnvironmentManifest> manifest;
95
100 std::optional<GlobalManifestRaw> globalManifestRaw;
101
103 std::optional<LockfileRaw> lockfileRaw;
104
106 std::optional<Lockfile> lockfile;
107
109 std::optional<Environment> environment;
110
111
112protected:
113
123 void
124 setGlobalManifestRaw( std::optional<std::filesystem::path> maybePath );
125
135 void
136 setGlobalManifestRaw( std::optional<GlobalManifestRaw> maybeRaw );
137
138
148 [[nodiscard]] virtual GlobalManifest
149 initGlobalManifest( GlobalManifestRaw manifestRaw );
150
160 void
161 setManifestRaw( std::optional<std::filesystem::path> maybePath );
162
172 void
173 setManifestRaw( std::optional<ManifestRaw> maybeRaw );
174
175
185 [[nodiscard]] virtual EnvironmentManifest
186 initManifest( ManifestRaw manifestRaw );
187
195 virtual void
196 setLockfileRaw( std::filesystem::path path );
197
204 virtual void
205 setLockfileRaw( LockfileRaw lockfileRaw );
206
212 [[nodiscard]] virtual Lockfile
213 initLockfile( LockfileRaw lockfileRaw );
214
215
216 [[nodiscard]] const std::optional<LockfileRaw> &
217 getLockfileRaw()
218 {
219 return this->lockfileRaw;
220 }
221
222
223public:
224
226 [[nodiscard]] const std::optional<GlobalManifestRaw> &
227 getGlobalManifestRaw()
228 {
229 return this->globalManifestRaw;
230 }
231
232
240 [[nodiscard]] const std::optional<GlobalManifest>
241 getGlobalManifest();
242
244 [[nodiscard]] const std::optional<ManifestRaw> &
245 getManifestRaw() const
246 {
247 return this->manifestRaw;
248 }
249
256 [[nodiscard]] const EnvironmentManifest &
257 getManifest();
258
266 [[nodiscard]] const std::optional<Lockfile> &
267 getLockfile();
268
278 [[nodiscard]] Environment &
279 getEnvironment();
280
281 /* -------------------------- argument parsers ---------------------------- */
282
289 argparse::Argument &
290 addGlobalManifestFileOption( argparse::ArgumentParser & parser );
291
298 argparse::Argument &
299 addManifestFileOption( argparse::ArgumentParser & parser );
300
307 argparse::Argument &
308 addManifestFileArg( argparse::ArgumentParser & parser, bool required = true );
309
315 argparse::Argument &
316 addLockfileOption( argparse::ArgumentParser & parser );
317
324 argparse::Argument &
325 addFloxDirectoryOption( argparse::ArgumentParser & parser );
326
327
328}; /* End class `EnvironmentMixin' */
329
330
331/* -------------------------------------------------------------------------- */
332
333class GAEnvironmentMixin : public EnvironmentMixin
334{
335
336private:
337
339 bool gaRegistry = false;
340
341
342protected:
343
350 [[nodiscard]] GlobalManifest
351 initGlobalManifest( GlobalManifestRaw manifestRaw ) override;
352
359 [[nodiscard]] EnvironmentManifest
360 initManifest( ManifestRaw manifestRaw ) override;
361
362
363public:
364
371 argparse::Argument &
372 addGARegistryOption( argparse::ArgumentParser & parser );
373
374}; /* End class `GAEnvironmentMixin' */
375
376
377/* -------------------------------------------------------------------------- */
378
379} // namespace flox::resolver
380
381
382/* -------------------------------------------------------------------------- *
383 *
384 *
385 *
386 * ========================================================================== */
Definition: mixins.hh:334
EnvironmentManifest initManifest(ManifestRaw manifestRaw) override
Initialize the manifest member variable. When --ga-registry is set it enforces a GA compliant manifes...
Definition: mixins.cc:377
GlobalManifest initGlobalManifest(GlobalManifestRaw manifestRaw) override
Initialize the globalManifest member variable. When --ga-registry is set it enforces a GA compliant m...
Definition: mixins.cc:360
argparse::Argument & addGARegistryOption(argparse::ArgumentParser &parser)
Hard codes a manifest with only github:NixOS/nixpkgs/release-23.05 with --ga-registry.
Definition: mixins.cc:395
bool gaRegistry
Definition: mixins.hh:339
Definition: manifest.hh:221
A collection of files associated with an environment.
Definitions of various std::exception children used for throwing errors with nice messages and typed ...
#define FLOX_DEFINE_EXCEPTION(NAME, ERROR_CODE, CATEGORY_MSG)
Generate a class definition with an error code and category message.
Definition: exceptions.hh:206
A lockfile representing a resolved environment.
An abstract description of an environment in its unresolved state.
@ EC_ENVIRONMENT_MIXIN
Definition: exceptions.hh:79
A global manifest containing only registry and options fields in its raw form.
Definition: manifest-raw.hh:133
A raw description of an environment to be read from a file.
Definition: manifest-raw.hh:264