15#include <nix/eval-cache.hh>
16#include <nix/flake/flake.hh>
19#include <nlohmann/json.hpp>
47using MaybeCursor = std::shared_ptr<nix::eval_cache::AttrCursor>;
50using Cursor = nix::ref<nix::eval_cache::AttrCursor>;
79 { { ST_NONE,
nullptr },
80 { ST_LEGACY,
"legacyPackages" },
81 { ST_PACKAGES,
"packages" } } )
91 constexpr Subtree() =
default;
94 constexpr Subtree(
subtree_type subtree ) : subtree( subtree ) {}
97 constexpr explicit Subtree( std::string_view str ) noexcept
98 : subtree( ( str ==
"legacyPackages" ) ? ST_LEGACY
99 : ( str ==
"packages" ) ? ST_PACKAGES
105 [[nodiscard]]
static Subtree
106 parseSubtree( std::string_view str )
108 return Subtree { ( str ==
"legacyPackages" ) ? ST_LEGACY
109 : ( str ==
"packages" )
111 :
throw std::invalid_argument(
112 "Invalid subtree '" + std::string( str ) +
"'" ) };
117 [[nodiscard]]
friend constexpr std::string_view
118 to_string(
const Subtree & subtree )
120 switch ( subtree.subtree )
122 case ST_LEGACY:
return "legacyPackages";
123 case ST_PACKAGES:
return "packages";
124 default:
return "ST_NONE";
130 operator std::string_view()
const
132 return to_string( *
this );
139 return this->subtree;
143 [[nodiscard]]
constexpr bool
144 operator==(
const Subtree & other )
const
148 [[nodiscard]]
constexpr bool
149 operator!=(
const Subtree & other )
const
153 [[nodiscard]]
constexpr bool
156 return this->subtree == other;
160 [[nodiscard]]
constexpr bool
163 return this->subtree != other;
173from_json(
const nlohmann::json & jfrom, Subtree & subtree )
175 jfrom.get_to( subtree.subtree );
180to_json( nlohmann::json & jto,
const Subtree & subtree )
182 to_json( jto, subtree.subtree );
Interfaces for use by flox.
Definition: command.cc:29
std::shared_ptr< nix::eval_cache::AttrCursor > MaybeCursor
A std::shared_ptr<nix::eval_cache::AttrCursor> which may be nullptr.
Definition: types.hh:47
subtree_type
A top level key in a nix flake.
Definition: types.hh:68
nix::ref< nix::eval_cache::AttrCursor > Cursor
A non-nullptr std::shared_ptr<nix::eval_cache::AttrCursor>.
Definition: types.hh:50
NLOHMANN_JSON_SERIALIZE_ENUM(subtree_type, { { ST_NONE, nullptr }, { ST_LEGACY, "legacyPackages" }, { ST_PACKAGES, "packages" } }) struct Subtree
A strongly typed wrapper over an attribute path subtree name, which is the first element of an attrib...
Definition: types.hh:78
std::string System
A system pair indicating architecture and platform.
Definition: types.hh:62
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
std::vector< std::string > AttrPath
A list of key names addressing a location in a nested JSON-like object.
Definition: types.hh:33