1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-02 21:51:50 +02:00

Make the store plugins more introspectable

Directly register the store classes rather than a function to build an
instance of them.
This gives the possibility to introspect static members of the class or
choose different ways of instantiating them.
This commit is contained in:
regnat 2020-09-08 14:50:23 +02:00
parent 609a6d6d9f
commit 7d5bdf8b56
18 changed files with 141 additions and 117 deletions

View file

@ -33,6 +33,7 @@ MakeError(SubstituteGone, Error);
MakeError(SubstituterDisabled, Error);
MakeError(BadStorePath, Error);
MakeError(InvalidStoreURI, Error);
class FSAccessor;
class NarInfoDiskCache;
@ -199,6 +200,8 @@ protected:
Store(const Params & params);
std::shared_ptr<Config> getConfig();
public:
virtual ~Store() { }
@ -744,25 +747,31 @@ StoreType getStoreType(const std::string & uri = settings.storeUri.get(),
substituters option and various legacy options. */
std::list<ref<Store>> getDefaultSubstituters();
struct StoreFactory
{
std::vector<std::string> uriPrefixes;
std::function<std::shared_ptr<Store> (const std::string & uri, const Store::Params & params)> open;
};
typedef std::vector<StoreFactory> Implementations;
static Implementations * implementations = new Implementations;
/* Store implementation registration. */
typedef std::function<std::shared_ptr<Store>(
const std::string & uri, const Store::Params & params)> OpenStore;
template<typename T>
struct RegisterStoreImplementation
{
typedef std::vector<OpenStore> Implementations;
static Implementations * implementations;
RegisterStoreImplementation(OpenStore fun)
RegisterStoreImplementation()
{
if (!implementations) implementations = new Implementations;
implementations->push_back(fun);
StoreFactory factory{
.uriPrefixes = T::uriPrefixes(),
.open =
([](const std::string & uri, const Store::Params & params)
-> std::shared_ptr<Store>
{ return std::make_shared<T>(uri, params); })
};
implementations->push_back(factory);
}
};
/* Display a set of paths in human-readable form (i.e., between quotes
and separated by commas). */
string showPaths(const PathSet & paths);