about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2018-02-13T12·51-0500
committerShea Levy <shea@shealevy.com>2018-02-13T16·25-0500
commitb8739f2fb33a28a250cd2053c013b977a3f096e8 (patch)
tree6c20e81253bd76ebc377c983d9c31d9946856902
parentf471aacff213047390951620f5f9799dc745f167 (diff)
Enable specifying directories in plugin-files.
-rw-r--r--doc/manual/command-ref/conf-file.xml4
-rw-r--r--src/libstore/globals.cc24
2 files changed, 22 insertions, 6 deletions
diff --git a/doc/manual/command-ref/conf-file.xml b/doc/manual/command-ref/conf-file.xml
index 5c4561f66d86..2b7a69a0c59e 100644
--- a/doc/manual/command-ref/conf-file.xml
+++ b/doc/manual/command-ref/conf-file.xml
@@ -764,6 +764,10 @@ builtins.fetchurl {
         should not be linked to any Nix libs directly, as those will
         be available already at load time.
       </para>
+      <para>
+	If an entry in the list is a directory, all files in the
+	directory are loaded as plugins (non-recursively).
+      </para>
     </listitem>
 
   </varlistentry>
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 21ab0e6296ef..c6b508cbe82f 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -142,12 +142,24 @@ void MaxBuildJobsSetting::set(const std::string & str)
 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());
+        Paths pluginFiles;
+        try {
+            auto ents = readDirectory(pluginFile);
+            for (const auto & ent : ents)
+                pluginFiles.emplace_back(pluginFile + "/" + ent.name);
+        } catch (SysError & e) {
+            if (e.errNo != ENOTDIR)
+                throw;
+            pluginFiles.emplace_back(pluginFile);
+        }
+        for (const auto & file : pluginFiles) {
+            /* handle is purposefully leaked as there may be state in the
+               DSO needed by the action of the plugin. */
+            void *handle =
+                dlopen(file.c_str(), RTLD_LAZY | RTLD_LOCAL);
+            if (!handle)
+                throw Error("could not dynamically open plugin file '%s%': %s%", file, dlerror());
+        }
     }
 }