about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-02-13T11·15+0100
committerEelco Dolstra <edolstra@gmail.com>2018-02-13T11·15+0100
commit1c10a74c73e710d164d9e5c527f98b309a6f7b2c (patch)
tree11d7729c31624fe452ef8ee1727bc16b229a2583 /src/libstore
parentc5cc57e96220cd3ed915875f3b1eeb2ba1f98a30 (diff)
parent88cd2d41acb994684a3e4ead1b1676019f43b4b6 (diff)
Merge branch 'plugins' of https://github.com/shlevy/nix
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/globals.cc15
-rw-r--r--src/libstore/globals.hh7
-rw-r--r--src/libstore/local.mk3
3 files changed, 25 insertions, 0 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index d3c96ddd6e61..21ab0e6296ef 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -6,6 +6,7 @@
 #include <algorithm>
 #include <map>
 #include <thread>
+#include <dlfcn.h>
 
 
 namespace nix {
@@ -137,4 +138,18 @@ void MaxBuildJobsSetting::set(const std::string & str)
         throw UsageError("configuration setting '%s' should be 'auto' or an integer", name);
 }
 
+
+void initPlugins()
+{
+    for (const auto & pluginFile : settings.pluginFiles.get()) {
+        /* handle is purposefully leaked as there may be state in the
+           DSO needed by the action of the plugin. */
+        void *handle =
+            dlopen(pluginFile.c_str(), RTLD_LAZY | RTLD_LOCAL);
+        if (!handle)
+            throw Error(format("could not dynamically open plugin file '%1%': %2%") % pluginFile % dlerror());
+    }
+}
+
+
 }
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index 20ac8fe4e9ae..508084d08acb 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -367,12 +367,19 @@ public:
 
     Setting<Strings> allowedUris{this, {}, "allowed-uris",
         "Prefixes of URIs that builtin functions such as fetchurl and fetchGit are allowed to fetch."};
+
+    Setting<Paths> pluginFiles{this, {}, "plugin-files",
+        "Plugins to dynamically load at nix initialization time."};
 };
 
 
 // FIXME: don't use a global variable.
 extern Settings settings;
 
+/* This should be called after settings are initialized, but before
+   anything else */
+void initPlugins();
+
 
 extern const string nixVersion;
 
diff --git a/src/libstore/local.mk b/src/libstore/local.mk
index 50c46ce6fe99..239356aee8dc 100644
--- a/src/libstore/local.mk
+++ b/src/libstore/local.mk
@@ -9,6 +9,9 @@ libstore_SOURCES := $(wildcard $(d)/*.cc)
 libstore_LIBS = libutil libformat
 
 libstore_LDFLAGS = $(SQLITE3_LIBS) -lbz2 $(LIBCURL_LIBS) $(SODIUM_LIBS) -pthread
+ifneq ($(OS), FreeBSD)
+ libstore_LDFLAGS += -ldl
+endif
 
 libstore_FILES = sandbox-defaults.sb sandbox-minimal.sb sandbox-network.sb