Merge branch 'plugins' of https://github.com/shlevy/nix
This commit is contained in:
		
						commit
						1c10a74c73
					
				
					 24 changed files with 122 additions and 3 deletions
				
			
		|  | @ -64,6 +64,8 @@ int main (int argc, char * * argv) | |||
| 
 | ||||
|         settings.maxBuildJobs.set("1"); // hack to make tests with local?root= work
 | ||||
| 
 | ||||
|         initPlugins(); | ||||
| 
 | ||||
|         auto store = openStore().cast<LocalStore>(); | ||||
| 
 | ||||
|         /* It would be more appropriate to use $XDG_RUNTIME_DIR, since
 | ||||
|  |  | |||
|  | @ -22,6 +22,7 @@ public: | |||
| 
 | ||||
| int handleExceptions(const string & programName, std::function<void()> fun); | ||||
| 
 | ||||
| /* Don't forget to call initPlugins() after settings are initialized! */ | ||||
| void initNix(); | ||||
| 
 | ||||
| void parseCmdLine(int argc, char * * argv, | ||||
|  |  | |||
|  | @ -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()); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -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; | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -232,6 +232,8 @@ void mainWrapped(int argc, char * * argv) | |||
| 
 | ||||
|     myArgs.parseCmdline(args); | ||||
| 
 | ||||
|     initPlugins(); | ||||
| 
 | ||||
|     if (packages && fromArgs) | ||||
|         throw UsageError("'-p' and '-E' are mutually exclusive"); | ||||
| 
 | ||||
|  |  | |||
|  | @ -213,6 +213,9 @@ int main(int argc, char ** argv) | |||
|             } | ||||
|             return true; | ||||
|         }); | ||||
| 
 | ||||
|         initPlugins(); | ||||
| 
 | ||||
|         switch (cmd) { | ||||
|             case cNone: | ||||
|                 throw UsageError("no command specified"); | ||||
|  |  | |||
|  | @ -77,6 +77,8 @@ int main(int argc, char * * argv) | |||
|             return true; | ||||
|         }); | ||||
| 
 | ||||
|         initPlugins(); | ||||
| 
 | ||||
|         auto profilesDir = settings.nixStateDir + "/profiles"; | ||||
|         if (removeOld) removeOldGenerations(profilesDir); | ||||
| 
 | ||||
|  |  | |||
|  | @ -44,6 +44,8 @@ int main(int argc, char ** argv) | |||
|             return true; | ||||
|         }); | ||||
| 
 | ||||
|         initPlugins(); | ||||
| 
 | ||||
|         if (sshHost.empty()) | ||||
|             throw UsageError("no host name specified"); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1060,6 +1060,8 @@ int main(int argc, char * * argv) | |||
|             return true; | ||||
|         }); | ||||
| 
 | ||||
|         initPlugins(); | ||||
| 
 | ||||
|         if (stdio) { | ||||
|             if (getStoreType() == tDaemon) { | ||||
|                 /* Forward on this connection to the real daemon */ | ||||
|  |  | |||
|  | @ -1393,6 +1393,8 @@ int main(int argc, char * * argv) | |||
| 
 | ||||
|         myArgs.parseCmdline(argvToStrings(argc, argv)); | ||||
| 
 | ||||
|         initPlugins(); | ||||
| 
 | ||||
|         if (!op) throw UsageError("no operation specified"); | ||||
| 
 | ||||
|         auto store = openStore(); | ||||
|  |  | |||
|  | @ -151,6 +151,8 @@ int main(int argc, char * * argv) | |||
| 
 | ||||
|         myArgs.parseCmdline(argvToStrings(argc, argv)); | ||||
| 
 | ||||
|         initPlugins(); | ||||
| 
 | ||||
|         if (evalOnly && !wantsReadWrite) | ||||
|             settings.readOnlyMode = true; | ||||
| 
 | ||||
|  |  | |||
|  | @ -89,6 +89,8 @@ int main(int argc, char * * argv) | |||
| 
 | ||||
|         myArgs.parseCmdline(argvToStrings(argc, argv)); | ||||
| 
 | ||||
|         initPlugins(); | ||||
| 
 | ||||
|         if (args.size() > 2) | ||||
|             throw UsageError("too many arguments"); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1052,6 +1052,8 @@ int main(int argc, char * * argv) | |||
|             return true; | ||||
|         }); | ||||
| 
 | ||||
|         initPlugins(); | ||||
| 
 | ||||
|         if (!op) throw UsageError("no operation specified"); | ||||
| 
 | ||||
|         if (op != opDump && op != opRestore) /* !!! hack */ | ||||
|  |  | |||
|  | @ -92,6 +92,8 @@ void mainWrapped(int argc, char * * argv) | |||
| 
 | ||||
|     args.parseCmdline(argvToStrings(argc, argv)); | ||||
| 
 | ||||
|     initPlugins(); | ||||
| 
 | ||||
|     if (!args.command) args.showHelpAndExit(); | ||||
| 
 | ||||
|     Finally f([]() { stopProgressBar(); }); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue