From 3b592c880ae76707cc832e5f227e261be29661bf Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 17 Apr 2023 11:58:47 -0400 Subject: [PATCH] Add infra for experimental store implemenations This is analogous to that for experimental settings and flags that we have also added as of late. --- doc/manual/generate-manpage.nix | 21 +++++++++++++++++++-- src/libstore/store-api.cc | 1 + src/libstore/store-api.hh | 15 +++++++++++++++ src/nix/main.cc | 6 ++++-- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/doc/manual/generate-manpage.nix b/doc/manual/generate-manpage.nix index fb34898f3..65eec42d0 100644 --- a/doc/manual/generate-manpage.nix +++ b/doc/manual/generate-manpage.nix @@ -137,12 +137,29 @@ let storeDocs = let - showStore = name: { settings, doc }: - '' + showStore = name: { settings, doc, experimentalFeature }: + let + experimentalFeatureNote = optionalString (experimentalFeature != null) '' + > **Warning** + > This store is part of an + > [experimental feature](@docroot@/contributing/experimental-features.md). + + To use this store, you need to make sure the corresponding experimental feature, + [`${experimentalFeature}`](@docroot@/contributing/experimental-features.md#xp-feature-${experimentalFeature}), + is enabled. + For example, include the following in [`nix.conf`](#): + + ``` + extra-experimental-features = ${experimentalFeature} + ``` + ''; + in '' ## ${name} ${doc} + ${experimentalFeatureNote} + **Settings**: ${showSettings { useAnchors = false; } settings} diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 4ea16a1c0..28689e100 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -1496,6 +1496,7 @@ ref openStore(const std::string & uri_, if (implem.uriSchemes.count(parsedUri.scheme)) { auto store = implem.create(parsedUri.scheme, baseURI, params); if (store) { + experimentalFeatureSettings.require(store->experimentalFeature()); store->init(); store->warnUnknownSettings(); return ref(store); diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 3758c730f..f9029ade1 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -109,13 +109,28 @@ struct StoreConfig : public Config virtual ~StoreConfig() { } + /** + * The name of this type of store. + */ virtual const std::string name() = 0; + /** + * Documentation for this type of store. + */ virtual std::string doc() { return ""; } + /** + * An experimental feature this type store is gated, if it is to be + * experimental. + */ + virtual std::optional experimentalFeature() const + { + return std::nullopt; + } + const PathSetting storeDir_{this, settings.nixStore, "store", R"( diff --git a/src/nix/main.cc b/src/nix/main.cc index df66beb8c..c5a9c8b33 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -180,8 +180,10 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs for (auto & implem : *Implementations::registered) { auto storeConfig = implem.getConfig(); auto storeName = storeConfig->name(); - stores[storeName]["doc"] = storeConfig->doc(); - stores[storeName]["settings"] = storeConfig->toJSON(); + auto & j = stores[storeName]; + j["doc"] = storeConfig->doc(); + j["settings"] = storeConfig->toJSON(); + j["experimentalFeature"] = storeConfig->experimentalFeature(); } res["stores"] = std::move(stores);