Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jul 21, 2024
1 parent cc1ce6a commit 53f692b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
20 changes: 15 additions & 5 deletions src/libstore/store-registration.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,44 @@ namespace nix {

struct StoreFactory
{
std::string doc;
std::set<std::string> uriSchemes;
config::SettingDescriptionMap configDescriptions;
std::optional<ExperimentalFeature> experimentalFeature;
/**
* The `authorityPath` parameter is `<authority>/<path>`, or really
* whatever comes after `<scheme>://` and before `?<query-params>`.
*/
std::function<ref<StoreConfig>(
std::string_view scheme, std::string_view authorityPath, const StoreReference::Params & params)>
parseConfig;
config::SettingDescriptionMap configDescriptions;
};

struct Implementations
{
static std::vector<StoreFactory> * registered;
private:

using V = std::vector<std::pair<std::string, StoreFactory>>;

public:

static V * registered;

template<typename TConfig>
static void add()
{
if (!registered)
registered = new std::vector<StoreFactory>();
registered = new V{};
StoreFactory factory{
.doc = TConfig::doc(),
.uriSchemes = TConfig::uriSchemes(),
.configDescriptions = TConfig::descriptions(),
.experimentalFeature = TConfig::experimentalFeature(),
.parseConfig = ([](auto scheme, auto uri, auto & params) -> ref<StoreConfig> {
return make_ref<TConfig>(scheme, uri, params);
}),
.configDescriptions = TConfig::descriptions(),
};
registered->push_back(factory);
registered->push_back({TConfig::name(), std::move(factory)});
}
};

Expand Down
13 changes: 5 additions & 8 deletions src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,12 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
res["args"] = toJSON();

auto stores = nlohmann::json::object();
for (auto & implem : *Implementations::registered) {
#if 0
auto storeConfig = implem.getConfig();
auto storeName = storeConfig->name();
for (auto & [storeName, implem] : *Implementations::registered) {
auto & j = stores[storeName];
j["doc"] = storeConfig->doc();
j["settings"] = storeConfig->toJSON();
j["experimentalFeature"] = storeConfig->experimentalFeature();
#endif
j["doc"] = implem.doc;
j["uri-schemes"] = implem.uriSchemes;
j["settings"] = implem.configDescriptions;
j["experimentalFeature"] = implem.experimentalFeature;
}
res["stores"] = std::move(stores);
res["fetchers"] = fetchers::dumpRegisterInputSchemeInfo();
Expand Down

0 comments on commit 53f692b

Please sign in to comment.