aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrebecca “wiggles” turner <rbt@sent.as>2024-08-28 16:43:22 +0000
committerGerrit Code Review <gerrit@localhost>2024-08-28 16:43:22 +0000
commit422550fd68a5877534b1ca577fc3c7d89b6706dd (patch)
treef800e0a34110e53c23bb230f11b33096b62ee344
parent5d31e889d7f3310cb030e85adcfd3ce64846457d (diff)
parent4f02255c205378427f5831463c0c07e45382b2b2 (diff)
Merge "libstore: remove static initializers for Store registrations" into main
-rw-r--r--src/libstore/dummy-store.cc5
-rw-r--r--src/libstore/dummy-store.hh8
-rw-r--r--src/libstore/globals.cc23
-rw-r--r--src/libstore/http-binary-cache-store.cc5
-rw-r--r--src/libstore/http-binary-cache-store.hh8
-rw-r--r--src/libstore/legacy-ssh-store.cc7
-rw-r--r--src/libstore/legacy-ssh-store.hh8
-rw-r--r--src/libstore/local-binary-cache-store.cc5
-rw-r--r--src/libstore/local-binary-cache-store.hh8
-rw-r--r--src/libstore/local-store.hh3
-rw-r--r--src/libstore/meson.build6
-rw-r--r--src/libstore/platform/darwin.cc5
-rw-r--r--src/libstore/platform/fallback.cc4
-rw-r--r--src/libstore/platform/linux.cc4
-rw-r--r--src/libstore/s3-binary-cache-store.cc8
-rw-r--r--src/libstore/s3-binary-cache-store.hh2
-rw-r--r--src/libstore/ssh-store.cc6
-rw-r--r--src/libstore/ssh-store.hh (renamed from src/libstore/ssh-store-config.hh)2
-rw-r--r--src/libstore/store-api.cc4
-rw-r--r--src/libstore/store-api.hh19
-rw-r--r--src/libstore/uds-remote-store.cc4
-rw-r--r--src/libstore/uds-remote-store.hh2
-rw-r--r--src/nix/main.cc2
23 files changed, 118 insertions, 30 deletions
diff --git a/src/libstore/dummy-store.cc b/src/libstore/dummy-store.cc
index e16f87e4b..f14b7ddd1 100644
--- a/src/libstore/dummy-store.cc
+++ b/src/libstore/dummy-store.cc
@@ -1,3 +1,4 @@
+#include "dummy-store.hh"
#include "store-api.hh"
namespace nix {
@@ -73,6 +74,8 @@ struct DummyStore : public virtual DummyStoreConfig, public virtual Store
{ unsupported("getFSAccessor"); }
};
-static RegisterStoreImplementation<DummyStore, DummyStoreConfig> regDummyStore;
+void registerDummyStore() {
+ StoreImplementations::add<DummyStore, DummyStoreConfig>();
+}
}
diff --git a/src/libstore/dummy-store.hh b/src/libstore/dummy-store.hh
new file mode 100644
index 000000000..355c011f8
--- /dev/null
+++ b/src/libstore/dummy-store.hh
@@ -0,0 +1,8 @@
+#pragma once
+///@file
+
+namespace nix {
+
+void registerDummyStore();
+
+}
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 6cfa3ffac..b534882de 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -33,6 +33,16 @@
#include <sys/sysctl.h>
#endif
+// All built-in store implementations.
+#include "dummy-store.hh"
+#include "http-binary-cache-store.hh"
+#include "legacy-ssh-store.hh"
+#include "local-binary-cache-store.hh"
+#include "local-store.hh"
+#include "s3-binary-cache-store.hh"
+#include "ssh-store.hh"
+#include "uds-remote-store.hh"
+
namespace nix {
@@ -396,6 +406,17 @@ static void preloadNSS()
});
}
+static void registerStoreImplementations() {
+ registerDummyStore();
+ registerHttpBinaryCacheStore();
+ registerLegacySSHStore();
+ registerLocalBinaryCacheStore();
+ registerLocalStore();
+ registerS3BinaryCacheStore();
+ registerSSHStore();
+ registerUDSRemoteStore();
+}
+
static bool initLibStoreDone = false;
void assertLibStoreInitialized() {
@@ -433,6 +454,8 @@ void initLibStore() {
unsetenv("TMPDIR");
#endif
+ registerStoreImplementations();
+
initLibStoreDone = true;
}
diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc
index 7ceea716a..c68faf552 100644
--- a/src/libstore/http-binary-cache-store.cc
+++ b/src/libstore/http-binary-cache-store.cc
@@ -1,3 +1,4 @@
+#include "http-binary-cache-store.hh"
#include "binary-cache-store.hh"
#include "filetransfer.hh"
#include "globals.hh"
@@ -194,6 +195,8 @@ protected:
}
};
-static RegisterStoreImplementation<HttpBinaryCacheStore, HttpBinaryCacheStoreConfig> regHttpBinaryCacheStore;
+void registerHttpBinaryCacheStore() {
+ StoreImplementations::add<HttpBinaryCacheStore, HttpBinaryCacheStoreConfig>();
+}
}
diff --git a/src/libstore/http-binary-cache-store.hh b/src/libstore/http-binary-cache-store.hh
new file mode 100644
index 000000000..097c5480b
--- /dev/null
+++ b/src/libstore/http-binary-cache-store.hh
@@ -0,0 +1,8 @@
+#pragma once
+///@file
+
+namespace nix {
+
+void registerHttpBinaryCacheStore();
+
+}
diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc
index 5650282d6..9e2d65a1c 100644
--- a/src/libstore/legacy-ssh-store.cc
+++ b/src/libstore/legacy-ssh-store.cc
@@ -1,4 +1,4 @@
-#include "ssh-store-config.hh"
+#include "legacy-ssh-store.hh"
#include "archive.hh"
#include "pool.hh"
#include "remote-store.hh"
@@ -8,6 +8,7 @@
#include "store-api.hh"
#include "path-with-outputs.hh"
#include "ssh.hh"
+#include "ssh-store.hh"
#include "derivations.hh"
namespace nix {
@@ -412,6 +413,8 @@ public:
{ unsupported("queryRealisation"); }
};
-static RegisterStoreImplementation<LegacySSHStore, LegacySSHStoreConfig> regLegacySSHStore;
+void registerLegacySSHStore() {
+ StoreImplementations::add<LegacySSHStore, LegacySSHStoreConfig>();
+}
}
diff --git a/src/libstore/legacy-ssh-store.hh b/src/libstore/legacy-ssh-store.hh
new file mode 100644
index 000000000..76298d8d9
--- /dev/null
+++ b/src/libstore/legacy-ssh-store.hh
@@ -0,0 +1,8 @@
+#pragma once
+///@file
+
+namespace nix {
+
+void registerLegacySSHStore();
+
+}
diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc
index 99dd0e0f6..2f6a092e1 100644
--- a/src/libstore/local-binary-cache-store.cc
+++ b/src/libstore/local-binary-cache-store.cc
@@ -1,3 +1,4 @@
+#include "local-binary-cache-store.hh"
#include "binary-cache-store.hh"
#include "globals.hh"
#include "nar-info-disk-cache.hh"
@@ -124,6 +125,8 @@ std::set<std::string> LocalBinaryCacheStore::uriSchemes()
return {"file"};
}
-static RegisterStoreImplementation<LocalBinaryCacheStore, LocalBinaryCacheStoreConfig> regLocalBinaryCacheStore;
+void registerLocalBinaryCacheStore() {
+ StoreImplementations::add<LocalBinaryCacheStore, LocalBinaryCacheStoreConfig>();
+}
}
diff --git a/src/libstore/local-binary-cache-store.hh b/src/libstore/local-binary-cache-store.hh
new file mode 100644
index 000000000..727d60cb3
--- /dev/null
+++ b/src/libstore/local-binary-cache-store.hh
@@ -0,0 +1,8 @@
+#pragma once
+///@file
+
+namespace nix {
+
+void registerLocalBinaryCacheStore();
+
+}
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index f6b553615..1913aa192 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -421,4 +421,7 @@ void canonicaliseTimestampAndPermissions(const Path & path);
MakeError(PathInUse, Error);
+// Implemented by the relevant platform/ module being used.
+void registerLocalStore();
+
}
diff --git a/src/libstore/meson.build b/src/libstore/meson.build
index 5416bd2b5..74f5cd04e 100644
--- a/src/libstore/meson.build
+++ b/src/libstore/meson.build
@@ -118,12 +118,16 @@ libstore_headers = files(
'derived-path-map.hh',
'derived-path.hh',
'downstream-placeholder.hh',
+ 'dummy-store.hh',
'filetransfer.hh',
'fs-accessor.hh',
'gc-store.hh',
'globals.hh',
+ 'http-binary-cache-store.hh',
'indirect-root-store.hh',
+ 'legacy-ssh-store.hh',
'length-prefixed-protocol-helper.hh',
+ 'local-binary-cache-store.hh',
'local-fs-store.hh',
'local-store.hh',
'lock.hh',
@@ -152,8 +156,8 @@ libstore_headers = files(
'serve-protocol-impl.hh',
'serve-protocol.hh',
'sqlite.hh',
- 'ssh-store-config.hh',
'ssh.hh',
+ 'ssh-store.hh',
'store-api.hh',
'store-cast.hh',
'uds-remote-store.hh',
diff --git a/src/libstore/platform/darwin.cc b/src/libstore/platform/darwin.cc
index 1f7e9be23..078753bff 100644
--- a/src/libstore/platform/darwin.cc
+++ b/src/libstore/platform/darwin.cc
@@ -261,4 +261,9 @@ void DarwinLocalDerivationGoal::execBuilder(std::string builder, Strings args, S
posix_spawn(nullptr, builder.c_str(), nullptr, &attrp, stringsToCharPtrs(args).data(), stringsToCharPtrs(envStrs).data());
}
+
+void registerLocalStore() {
+ StoreImplementations::add<DarwinLocalStore, LocalStoreConfig>();
+}
+
}
diff --git a/src/libstore/platform/fallback.cc b/src/libstore/platform/fallback.cc
index 5a01d64c8..0593ec204 100644
--- a/src/libstore/platform/fallback.cc
+++ b/src/libstore/platform/fallback.cc
@@ -1,5 +1,7 @@
#include "platform/fallback.hh"
namespace nix {
-static RegisterStoreImplementation<FallbackLocalStore, LocalStoreConfig> regLocalStore;
+void registerLocalStore() {
+ Implementations::add<FallbackLocalStore, LocalStoreConfig>();
+}
}
diff --git a/src/libstore/platform/linux.cc b/src/libstore/platform/linux.cc
index 03b8bc0be..f22fbe58f 100644
--- a/src/libstore/platform/linux.cc
+++ b/src/libstore/platform/linux.cc
@@ -25,7 +25,9 @@ namespace {
constexpr const std::string_view nativeSystem = SYSTEM;
}
-static RegisterStoreImplementation<LinuxLocalStore, LocalStoreConfig> regLocalStore;
+void registerLocalStore() {
+ StoreImplementations::add<LinuxLocalStore, LocalStoreConfig>();
+}
static void readProcLink(const std::string & file, UncheckedRoots & roots)
{
diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc
index ffebfda8d..921a2e556 100644
--- a/src/libstore/s3-binary-cache-store.cc
+++ b/src/libstore/s3-binary-cache-store.cc
@@ -526,8 +526,14 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStoreConfig, public virtual
};
-static RegisterStoreImplementation<S3BinaryCacheStoreImpl, S3BinaryCacheStoreConfig> regS3BinaryCacheStore;
+void registerS3BinaryCacheStore() {
+ StoreImplementations::add<S3BinaryCacheStoreImpl, S3BinaryCacheStoreConfig>();
+}
}
+#else
+namespace nix {
+void registerS3BinaryCacheStore() {}
+}
#endif
diff --git a/src/libstore/s3-binary-cache-store.hh b/src/libstore/s3-binary-cache-store.hh
index c62ea5147..baf21e2f4 100644
--- a/src/libstore/s3-binary-cache-store.hh
+++ b/src/libstore/s3-binary-cache-store.hh
@@ -29,4 +29,6 @@ public:
virtual const Stats & getS3Stats() = 0;
};
+void registerS3BinaryCacheStore();
+
}
diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc
index 80d10eb0f..94c0b7237 100644
--- a/src/libstore/ssh-store.cc
+++ b/src/libstore/ssh-store.cc
@@ -1,4 +1,4 @@
-#include "ssh-store-config.hh"
+#include "ssh-store.hh"
#include "store-api.hh"
#include "local-fs-store.hh"
#include "remote-store.hh"
@@ -110,6 +110,8 @@ ref<RemoteStore::Connection> SSHStore::openConnection()
return conn;
}
-static RegisterStoreImplementation<SSHStore, SSHStoreConfig> regSSHStore;
+void registerSSHStore() {
+ StoreImplementations::add<SSHStore, SSHStoreConfig>();
+}
}
diff --git a/src/libstore/ssh-store-config.hh b/src/libstore/ssh-store.hh
index bf55d20cf..51951f80b 100644
--- a/src/libstore/ssh-store-config.hh
+++ b/src/libstore/ssh-store.hh
@@ -26,4 +26,6 @@ struct CommonSSHStoreConfig : virtual StoreConfig
)"};
};
+void registerSSHStore();
+
}
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 6d9fec41b..f921956e8 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -1472,7 +1472,7 @@ ref<Store> openStore(const std::string & uri_,
parsedUri.authority.value_or("") + parsedUri.path
);
- for (auto implem : *Implementations::registered) {
+ for (auto implem : *StoreImplementations::registered) {
if (implem.uriSchemes.count(parsedUri.scheme)) {
auto store = implem.create(parsedUri.scheme, baseURI, params);
if (store) {
@@ -1526,6 +1526,6 @@ std::list<ref<Store>> getDefaultSubstituters()
return stores;
}
-std::vector<StoreFactory> * Implementations::registered = 0;
+std::vector<StoreFactory> * StoreImplementations::registered = 0;
}
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index efd0e4d9b..2da5cac39 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -50,11 +50,9 @@ namespace nix {
* that calls `StoreConfig(params)` (otherwise you're gonna encounter an
* `assertion failure` when trying to instantiate it).
*
- * You can then register the new store using:
- *
- * ```
- * cpp static RegisterStoreImplementation<Foo, FooConfig> regStore;
- * ```
+ * You can then register the new store by defining a registration function
+ * (using `StoreImplementations::add`) and calling it in
+ * `registerStoreImplementations` in `globals.cc`.
*/
MakeError(SubstError, Error);
@@ -1004,7 +1002,7 @@ struct StoreFactory
std::function<std::shared_ptr<StoreConfig> ()> getConfig;
};
-struct Implementations
+struct StoreImplementations
{
static std::vector<StoreFactory> * registered;
@@ -1027,15 +1025,6 @@ struct Implementations
}
};
-template<typename T, typename TConfig>
-struct RegisterStoreImplementation
-{
- RegisterStoreImplementation()
- {
- Implementations::add<T, TConfig>();
- }
-};
-
/**
* Display a set of paths in human-readable form (i.e., between quotes
diff --git a/src/libstore/uds-remote-store.cc b/src/libstore/uds-remote-store.cc
index 226cdf717..44dd45e88 100644
--- a/src/libstore/uds-remote-store.cc
+++ b/src/libstore/uds-remote-store.cc
@@ -88,6 +88,8 @@ void UDSRemoteStore::addIndirectRoot(const Path & path)
}
-static RegisterStoreImplementation<UDSRemoteStore, UDSRemoteStoreConfig> regUDSRemoteStore;
+void registerUDSRemoteStore() {
+ StoreImplementations::add<UDSRemoteStore, UDSRemoteStoreConfig>();
+}
}
diff --git a/src/libstore/uds-remote-store.hh b/src/libstore/uds-remote-store.hh
index ff7e9ae3f..8b56e0af0 100644
--- a/src/libstore/uds-remote-store.hh
+++ b/src/libstore/uds-remote-store.hh
@@ -63,4 +63,6 @@ private:
std::optional<std::string> path;
};
+void registerUDSRemoteStore();
+
}
diff --git a/src/nix/main.cc b/src/nix/main.cc
index e84e4f310..05c40db03 100644
--- a/src/nix/main.cc
+++ b/src/nix/main.cc
@@ -201,7 +201,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
res["args"] = toJSON();
auto stores = nlohmann::json::object();
- for (auto & implem : *Implementations::registered) {
+ for (auto & implem : *StoreImplementations::registered) {
auto storeConfig = implem.getConfig();
auto storeName = storeConfig->name();
auto & j = stores[storeName];