Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
package.hh
Go to the documentation of this file.
1/* ========================================================================== *
2 *
3 * @file flox/package.hh
4 *
5 * @brief Abstract representation of a package.
6 *
7 *
8 * -------------------------------------------------------------------------- */
9
10#pragma once
11
12#include <functional>
13#include <optional>
14#include <string>
15#include <variant>
16#include <vector>
17
18#include <nlohmann/json_fwd.hpp>
19
20#include <nix/eval-cache.hh>
21#include <nix/fetchers.hh>
22#include <nix/flake/flake.hh>
23#include <nix/names.hh>
24
26#include "flox/core/types.hh"
27#include "versions.hh"
28
29
30/* -------------------------------------------------------------------------- */
31
32namespace flox {
33
34/* -------------------------------------------------------------------------- */
35
44{
45
46public:
47
48 virtual ~Package() = default;
49 Package() = default;
50 Package( const Package & ) = default;
51 Package( Package && ) = default;
52
53 Package &
54 operator=( const Package & )
55 = default;
56 Package &
57 operator=( Package && )
58 = default;
59
61 [[nodiscard]] virtual AttrPath
63 = 0;
64
66 [[nodiscard]] virtual std::string
68 = 0;
69
75 [[nodiscard]] virtual std::string
76 getPname() const
77 = 0;
78
86 [[nodiscard]] virtual std::optional<std::string>
87 getVersion() const = 0;
88
91 [[nodiscard]] virtual std::optional<std::string>
92 getLicense() const = 0;
93
95 [[nodiscard]] virtual std::vector<std::string>
96 getOutputs() const = 0;
97
103 [[nodiscard]] virtual std::vector<std::string>
105
107 [[nodiscard]] virtual std::optional<bool>
108 isBroken() const = 0;
109
111 [[nodiscard]] virtual std::optional<bool>
112 isUnfree() const = 0;
113
118 [[nodiscard]] virtual std::optional<std::string>
119 getDescription() const = 0;
120
125 [[nodiscard]] virtual Subtree
127 {
128 return Subtree( this->getPathStrs().front() );
129 }
130
135 [[nodiscard]] virtual nix::DrvName
137 {
138 return { this->getFullName() };
139 }
140
146 [[nodiscard]] virtual std::optional<std::string>
147 getSemver() const
148 {
149 std::optional<std::string> version = this->getVersion();
150 if ( ! version.has_value() ) { return std::nullopt; }
151 return versions::coerceSemver( *version );
152 }
153
161 [[nodiscard]] virtual std::string
162 toURIString( const nix::FlakeRef & ref ) const;
163
171 [[nodiscard]] virtual nlohmann::json
172 getInfo( bool withDescription = false ) const;
173
174
175}; /* End class `Package' */
176
177
178/* -------------------------------------------------------------------------- */
179
180} // namespace flox
181
182
183/* -------------------------------------------------------------------------- *
184 *
185 *
186 *
187 * ========================================================================== */
Abstract representation of a "package", analogous to a Nix ‘derivation’.
Definition: package.hh:44
virtual nlohmann::json getInfo(bool withDescription=false) const
Serialize notable package metadata as a JSON object.
Definition: package.cc:39
virtual std::optional< std::string > getSemver() const
Definition: package.hh:147
virtual nix::DrvName getParsedDrvName() const
Definition: package.hh:136
virtual std::string getFullName() const =0
virtual std::optional< bool > isBroken() const =0
virtual AttrPath getPathStrs() const =0
virtual std::optional< std::string > getLicense() const =0
virtual std::vector< std::string > getOutputsToInstall() const =0
virtual std::optional< std::string > getVersion() const =0
virtual std::vector< std::string > getOutputs() const =0
virtual Subtree getSubtreeType() const
Definition: package.hh:126
virtual std::optional< bool > isUnfree() const =0
virtual std::optional< std::string > getDescription() const =0
virtual std::string getPname() const =0
virtual std::string toURIString(const nix::FlakeRef &ref) const
Create an installable URI string associated with this package using ref as its input part.
Definition: package.cc:22
Definitions of various std::exception children used for throwing errors with nice messages and typed ...
Interfaces for use by flox.
Definition: command.cc:29
std::vector< std::string > AttrPath
A list of key names addressing a location in a nested JSON-like object.
Definition: types.hh:33
std::optional< std::string > coerceSemver(std::string_view version)
Attempt to coerce strings such as "v1.0.2" or 1.0 to valid semantic version strings.
Definition: versions.cc:92
Miscellaneous typedefs and aliases.
Interfaces used to perform version number analysis, especially Semantic Version processing.