From f0a176e2f1061475546ade22b81343e4b4967568 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 8 May 2023 10:20:06 -0400 Subject: [PATCH] Init local overlay store --- src/libstore/local-overlay-store.cc | 20 ++++++++ src/libstore/local-overlay-store.hh | 74 +++++++++++++++++++++++++++++ src/libstore/store-api.cc | 3 ++ 3 files changed, 97 insertions(+) create mode 100644 src/libstore/local-overlay-store.cc create mode 100644 src/libstore/local-overlay-store.hh diff --git a/src/libstore/local-overlay-store.cc b/src/libstore/local-overlay-store.cc new file mode 100644 index 000000000..4cb50aef0 --- /dev/null +++ b/src/libstore/local-overlay-store.cc @@ -0,0 +1,20 @@ +#include "local-overlay-store.hh" + +namespace nix { + +LocalOverlayStore::LocalOverlayStore(const Params & params) + : StoreConfig(params) + , LocalFSStoreConfig(params) + , LocalStoreConfig(params) + , LocalOverlayStoreConfig(params) + , Store(params) + , LocalFSStore(params) + , LocalStore(params) + , lowerStore(openStore(lowerStoreUri).dynamic_pointer_cast()) +{ +} + + +static RegisterStoreImplementation regLocalOverlayStore; + +} diff --git a/src/libstore/local-overlay-store.hh b/src/libstore/local-overlay-store.hh new file mode 100644 index 000000000..3129bb7a0 --- /dev/null +++ b/src/libstore/local-overlay-store.hh @@ -0,0 +1,74 @@ +#include "local-store.hh" + +namespace nix { + +/** + * Configuration for `LocalOverlayStore`. + */ +struct LocalOverlayStoreConfig : virtual LocalStoreConfig +{ + // FIXME why doesn't this work? + // using LocalStoreConfig::LocalStoreConfig; + + LocalOverlayStoreConfig(const StringMap & params) + : StoreConfig(params) + , LocalFSStoreConfig(params) + , LocalStoreConfig(params) + { } + + const Setting lowerStoreUri{(StoreConfig*) this, "", "lower-store", + R"( + [Store URL](@docroot@/command-ref/new-cli/nix3-help-stores.md#store-url-format) + for the lower store. The default is `auto` (i.e. use the Nix daemon or `/nix/store` directly). + + Must be a store with a store dir on the file system. + )"}; + + const std::string name() override { return "Experimental Local Overlay Store"; } + + std::string doc() override + { + return + "" + // FIXME write docs + //#include "local-overlay-store.md" + ; + } +}; + +/** + * Variation of local store using overlayfs for the store dir. + */ +class LocalOverlayStore : public virtual LocalOverlayStoreConfig, public virtual LocalStore +{ + /** + * The store beneath us. + * + * Our store dir should be an overlay fs where the lower layer + * is that store's store dir, and the upper layer is some + * scratch storage just for us. + */ + ref lowerStore; + +public: + LocalOverlayStore(const Params & params); + + LocalOverlayStore(std::string scheme, std::string path, const Params & params) + : LocalOverlayStore(params) + { + throw UnimplementedError("LocalOverlayStore"); + } + + static std::set uriSchemes() + { return {}; } + + std::string getUri() override + { + return "local-overlay"; + } + +private: + // Overridden methods… +}; + +} diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 8fc3ed46a..c9ea03a1a 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -10,6 +10,7 @@ #include "archive.hh" #include "callback.hh" #include "remote-store.hh" +#include "local-overlay-store.hh" #include #include @@ -1391,6 +1392,8 @@ std::shared_ptr openFromNonUri(const std::string & uri, const Store::Para return std::make_shared(params); } else if (uri == "local") { return std::make_shared(params); + } else if (uri == "local-overlay") { + return std::make_shared(params); } else if (isNonUriPath(uri)) { Store::Params params2 = params; params2["root"] = absPath(uri);