18#include <nix/fetchers.hh>
19#include <nix/flake/flakeref.hh>
20#include <nlohmann/json.hpp>
60 const std::optional<std::vector<Subtree>> &
subtrees )
92 return this->subtrees == other.
subtrees;
96 operator!=(
const InputPreferences & other )
const
98 return ! ( ( *this ) == other );
109from_json(
const nlohmann::json & jfrom, InputPreferences & prefs );
113to_json( nlohmann::json & jto,
const InputPreferences & prefs );
124 = std::is_base_of<InputPreferences, T>::value &&
requires( T obj ) {
127 } -> std::convertible_to<nix::ref<nix::FlakeRef>>;
141 std::shared_ptr<nix::FlakeRef>
from;
146 const nix::FlakeRef &
from )
148 ,
from( std::make_shared<nix::FlakeRef>(
from ) )
152 :
from( std::make_shared<nix::FlakeRef>(
from ) )
157 [[nodiscard]] nix::ref<nix::FlakeRef>
160 return static_cast<nix::ref<nix::FlakeRef>
>( this->
from );
172 if ( this->from == other.
from ) {
return true; }
174 if ( ( this->from ==
nullptr ) || ( other.
from ==
nullptr ) )
179 return ( *this->from ) == ( *other.
from );
183 operator!=(
const RegistryInput & other )
const
185 return ! ( ( *this ) == other );
196from_json(
const nlohmann::json & jfrom, RegistryInput & rip );
200to_json( nlohmann::json & jto,
const RegistryInput & rip );
225 requires {
typename T::input_type; } &&
229 requires( T ref,
const std::string & name,
const RegistryInput & rip ) {
231 ref.mkInput( name, rip )
232 } -> std::convertible_to<std::shared_ptr<typename T::input_type>>;
250 [[nodiscard]]
static std::shared_ptr<RegistryInput>
253 return std::make_shared<RegistryInput>( input );
259static_assert( registry_input_factory<RegistryInputFactory> );
300 std::map<std::string, RegistryInput>
inputs;
328 std::vector<std::string>
priority = {} )
334 explicit RegistryRaw( std::map<std::string, RegistryInput>
inputs,
335 std::vector<std::string>
priority = {} )
336 : RegistryRaw( std::move(
inputs ),
373 [[nodiscard]]
virtual std::vector<std::reference_wrapper<const std::string>>
387 pkgdb::PkgQueryArgs &
389 pkgdb::PkgQueryArgs & pqa )
const;
398 merge(
const RegistryRaw & overrides );
401 operator==(
const RegistryRaw & other )
const;
404 operator!=(
const RegistryRaw & other )
const
406 return ! ( *
this == other );
417from_json(
const nlohmann::json & jfrom, RegistryRaw & reg );
421to_json( nlohmann::json & jto,
const RegistryRaw & reg );
448template<registry_input_factory FactoryType>
458 RegistryRaw registryRaw;
462 std::pair<std::string, std::shared_ptr<typename FactoryType::input_type>>>
468 using input_type =
typename FactoryType::input_type;
475 explicit Registry( RegistryRaw registry, FactoryType & factory )
476 : registryRaw( std::move( registry ) )
478 for (
const std::reference_wrapper<const std::string> & _name :
479 this->registryRaw.getOrder() )
481 const auto & pair = std::find_if(
482 this->registryRaw.inputs.begin(),
483 this->registryRaw.inputs.end(),
484 [&](
const auto & pair ) { return pair.first == _name.get(); } );
487 if ( pair->second.getFlakeRef()->input.getType() ==
"indirect" )
490 "registry contained an indirect reference" );
494 RegistryInput input = pair->second;
495 if ( ! input.subtrees.has_value() )
497 input.subtrees = this->registryRaw.defaults.subtrees;
501 this->inputs.emplace_back(
502 std::make_pair( pair->first,
503 factory.mkInput( pair->first, input ) ) );
513 [[nodiscard]] std::shared_ptr<typename FactoryType::input_type>
514 get(
const std::string & name )
const noexcept
516 const auto maybeInput
517 = std::find_if( this->inputs.begin(),
519 [&](
const auto & pair ) { return pair.first == name; } );
520 if ( maybeInput == this->inputs.end() ) {
return nullptr; }
521 return maybeInput->second;
529 [[nodiscard]] std::shared_ptr<typename FactoryType::input_type>
530 at(
const std::string & name )
const
532 const std::shared_ptr<typename FactoryType::input_type> maybeInput
534 if ( maybeInput ==
nullptr )
536 throw std::out_of_range(
"No such input '" + name +
"'" );
542 [[nodiscard]]
const RegistryRaw &
545 return this->registryRaw;
554 return this->inputs.size();
561 return this->inputs.empty();
568 return this->inputs.begin();
575 return this->inputs.end();
582 return this->inputs.cbegin();
592 return this->inputs.cend();
599 return this->inputs.cbegin();
609 return this->inputs.cend();
655 [[nodiscard]] nix::ref<FloxFlake>
668 [[nodiscard]]
const std::vector<Subtree> &
698 [[nodiscard]] std::shared_ptr<FloxFlakeInput>
701 return std::make_shared<FloxFlakeInput>( this->
getStore(), input );
708static_assert( registry_input_factory<FloxFlakeInputFactory> );
725 : Registry<FloxFlakeInputFactory>( std::move( registryRaw ), factory )
728 [[nodiscard]] std::map<std::string, RegistryInput>
740 const nix::ref<nix::Store> & store =
NixStoreMixin().getStore() );
A registry containing FloxFlakeInput members.
Definition: registry.hh:720
An exception thrown when a registry has invalid contents.
Mixin which provides a lazy handle to a nix store connection.
Definition: nix-state.hh:59
std::shared_ptr< nix::Store > store
Definition: nix-state.hh:63
nix::ref< nix::Store > getStore()
Lazily open a nix store connection.
Definition: nix-state.hh:106
Provides backports of some concepts features that are missing in Clang v11.
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
Defines a convenience wrapper that provides various operations on a flake.
Interfaces for use by flox.
Definition: command.cc:29
RegistryRaw lockRegistry(const RegistryRaw &unlocked, const nix::ref< nix::Store > &store)
Lock an unlocked registry.
Definition: registry.cc:365
@ EC_INVALID_REGISTRY
Definition: exceptions.hh:43
RegistryRaw getGARegistry()
Get a hard coded registry for use with flox's GA release.
Definition: registry.cc:377
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.
Definition: registry.hh:297
virtual std::vector< std::reference_wrapper< const std::string > > getOrder() const
Return an ordered list of input names.
Definition: registry.cc:73
void merge(const RegistryRaw &overrides)
Merge this flox::RegistryRaw struct with another flox::RegistryRaw, overriding any existing values wi...
Definition: registry.cc:247
std::vector< std::string > priority
Definition: registry.hh:310
pkgdb::PkgQueryArgs & fillPkgQueryArgs(const std::string &input, pkgdb::PkgQueryArgs &pqa) const
Fill a flox::pkgdb::PkgQueryArgs struct with preferences to lookup packages in a particular input.
Definition: registry.cc:225
virtual void clear()
Reset to default state.
Definition: registry.cc:62
InputPreferences defaults
Definition: registry.hh:303
std::map< std::string, RegistryInput > inputs
Definition: registry.hh:300
Miscellaneous typedefs and aliases.
Miscellaneous helper functions.