chore(3p/nix): Remove support for plugins
Plugins seem to not really be used anywhere (I can find one plugin that's actually defined, and it doesn't seem very useful, especially since we got rid of builtins.exec) and their presence is adding additional complexity and potential sources of bugs to an already unsteady refactor. At some point we may want to bring back something *like* plugins, but their design will likely be different and it will definitely be after we have a functioning Nix again. Change-Id: I3bc40e55917f70bf260fbc208c1705e2e6a7c626 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1291 Tested-by: BuildkiteCI Reviewed-by: Alyssa Ross <hi@alyssa.is> Reviewed-by: isomer <isomer@tvl.fyi>
This commit is contained in:
parent
31516eb9cd
commit
2ef1060361
18 changed files with 1 additions and 128 deletions
|
@ -598,37 +598,6 @@ password <replaceable>my-password</replaceable>
|
|||
</varlistentry>
|
||||
|
||||
|
||||
<varlistentry xml:id="conf-plugin-files">
|
||||
<term><literal>plugin-files</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
A list of plugin files to be loaded by Nix. Each of these
|
||||
files will be dlopened by Nix, allowing them to affect
|
||||
execution through static initialization. In particular, these
|
||||
plugins may construct static instances of RegisterPrimOp to
|
||||
add new primops or constants to the expression language,
|
||||
RegisterStoreImplementation to add new store implementations,
|
||||
RegisterCommand to add new subcommands to the
|
||||
<literal>nix</literal> command, and RegisterSetting to add new
|
||||
nix config settings. See the constructors for those types for
|
||||
more details.
|
||||
</para>
|
||||
<para>
|
||||
Since these files are loaded into the same address space as
|
||||
Nix itself, they must be DSOs compatible with the instance of
|
||||
Nix running at the time (i.e. compiled against the same
|
||||
headers, not linked to any incompatible libraries). They
|
||||
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>
|
||||
|
||||
<varlistentry xml:id="conf-pre-build-hook"><term><literal>pre-build-hook</literal></term>
|
||||
|
||||
<listitem>
|
||||
|
|
|
@ -68,8 +68,6 @@ static 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
|
||||
|
|
4
third_party/nix/src/libexpr/primops.hh
vendored
4
third_party/nix/src/libexpr/primops.hh
vendored
|
@ -14,9 +14,7 @@ struct RegisterPrimOp {
|
|||
RegisterPrimOp(const std::string& name, size_t arity, PrimOpFun fun);
|
||||
};
|
||||
|
||||
/* These primops are disabled without enableNativeCode, but plugins
|
||||
may wish to use them in limited contexts without globally enabling
|
||||
them. */
|
||||
/* These primops are disabled without enableNativeCode */
|
||||
/* Load a ValueInitializer from a DSO and return whatever it initializes */
|
||||
void prim_importNative(EvalState& state, const Pos& pos, Value** args,
|
||||
Value& v);
|
||||
|
|
1
third_party/nix/src/libmain/shared.hh
vendored
1
third_party/nix/src/libmain/shared.hh
vendored
|
@ -22,7 +22,6 @@ class Exit : public std::exception {
|
|||
int handleExceptions(const std::string& programName,
|
||||
const std::function<void()>& fun);
|
||||
|
||||
/* Don't forget to call initPlugins() after settings are initialized! */
|
||||
void initNix();
|
||||
|
||||
void parseCmdLine(
|
||||
|
|
31
third_party/nix/src/libstore/globals.cc
vendored
31
third_party/nix/src/libstore/globals.cc
vendored
|
@ -167,35 +167,4 @@ void MaxBuildJobsSetting::set(const std::string& str) {
|
|||
}
|
||||
}
|
||||
|
||||
void initPlugins() {
|
||||
for (const auto& pluginFile : settings.pluginFiles.get()) {
|
||||
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 == nullptr) {
|
||||
throw Error("could not dynamically open plugin file '%s': %s", file,
|
||||
dlerror());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Since plugins can add settings, try to re-apply previously
|
||||
unknown settings. */
|
||||
globalConfig.reapplyUnknownSettings();
|
||||
globalConfig.warnUnknownSettings();
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
|
|
10
third_party/nix/src/libstore/globals.hh
vendored
10
third_party/nix/src/libstore/globals.hh
vendored
|
@ -452,21 +452,11 @@ class Settings : public Config {
|
|||
Setting<uint64_t> minFreeCheckInterval{
|
||||
this, 5, "min-free-check-interval",
|
||||
"Number of seconds between checking free disk space."};
|
||||
|
||||
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();
|
||||
|
||||
void loadConfFile();
|
||||
|
||||
extern const std::string nixVersion;
|
||||
|
|
2
third_party/nix/src/nix-build/nix-build.cc
vendored
2
third_party/nix/src/nix-build/nix-build.cc
vendored
|
@ -255,8 +255,6 @@ static void _main(int argc, char** argv) {
|
|||
|
||||
myArgs.parseCmdline(args);
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (packages && fromArgs) {
|
||||
throw UsageError("'-p' and '-E' are mutually exclusive");
|
||||
}
|
||||
|
|
|
@ -214,8 +214,6 @@ static int _main(int argc, char** argv) {
|
|||
return true;
|
||||
});
|
||||
|
||||
initPlugins();
|
||||
|
||||
switch (cmd) {
|
||||
case cNone:
|
||||
throw UsageError("no command specified");
|
||||
|
|
|
@ -82,8 +82,6 @@ static int _main(int argc, char** argv) {
|
|||
return true;
|
||||
});
|
||||
|
||||
initPlugins();
|
||||
|
||||
auto profilesDir = settings.nixStateDir + "/profiles";
|
||||
if (removeOld) {
|
||||
removeOldGenerations(profilesDir);
|
||||
|
|
|
@ -48,8 +48,6 @@ static int _main(int argc, char** argv) {
|
|||
return true;
|
||||
});
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (sshHost.empty()) {
|
||||
throw UsageError("no host name specified");
|
||||
}
|
||||
|
|
2
third_party/nix/src/nix-daemon/nix-daemon.cc
vendored
2
third_party/nix/src/nix-daemon/nix-daemon.cc
vendored
|
@ -1107,8 +1107,6 @@ static int _main(int argc, char** argv) {
|
|||
return true;
|
||||
});
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (stdio) {
|
||||
if (getStoreType() == tDaemon) {
|
||||
/* Forward on this connection to the real daemon */
|
||||
|
|
2
third_party/nix/src/nix-env/nix-env.cc
vendored
2
third_party/nix/src/nix-env/nix-env.cc
vendored
|
@ -1496,8 +1496,6 @@ static int _main(int argc, char** argv) {
|
|||
|
||||
myArgs.parseCmdline(argvToStrings(argc, argv));
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (op == nullptr) {
|
||||
throw UsageError("no operation specified");
|
||||
}
|
||||
|
|
|
@ -153,8 +153,6 @@ static int _main(int argc, char** argv) {
|
|||
|
||||
myArgs.parseCmdline(argvToStrings(argc, argv));
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (evalOnly && !wantsReadWrite) {
|
||||
settings.readOnlyMode = true;
|
||||
}
|
||||
|
|
|
@ -100,8 +100,6 @@ static int _main(int argc, char** argv) {
|
|||
|
||||
myArgs.parseCmdline(argvToStrings(argc, argv));
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (args.size() > 2) {
|
||||
throw UsageError("too many arguments");
|
||||
}
|
||||
|
|
2
third_party/nix/src/nix-store/nix-store.cc
vendored
2
third_party/nix/src/nix-store/nix-store.cc
vendored
|
@ -1276,8 +1276,6 @@ static int _main(int argc, char** argv) {
|
|||
return true;
|
||||
});
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (op == nullptr) {
|
||||
throw UsageError("no operation specified");
|
||||
}
|
||||
|
|
2
third_party/nix/src/nix/main.cc
vendored
2
third_party/nix/src/nix/main.cc
vendored
|
@ -144,8 +144,6 @@ void mainWrapped(int argc, char** argv) {
|
|||
|
||||
args.parseCmdline(argvToStrings(argc, argv));
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (!args.command) {
|
||||
args.showHelpAndExit();
|
||||
}
|
||||
|
|
7
third_party/nix/tests/plugins.sh
vendored
7
third_party/nix/tests/plugins.sh
vendored
|
@ -1,7 +0,0 @@
|
|||
source common.sh
|
||||
|
||||
set -o pipefail
|
||||
|
||||
res=$(nix eval '(builtins.anotherNull)' --option setting-set true --option plugin-files $PWD/plugins/libplugintest*)
|
||||
|
||||
[ "$res"x = "nullx" ]
|
23
third_party/nix/tests/plugins/plugintest.cc
vendored
23
third_party/nix/tests/plugins/plugintest.cc
vendored
|
@ -1,23 +0,0 @@
|
|||
#include "libutil/config.hh"
|
||||
#include "primops.hh"
|
||||
|
||||
using namespace nix;
|
||||
|
||||
struct MySettings : Config {
|
||||
Setting<bool> settingSet{this, false, "setting-set",
|
||||
"Whether the plugin-defined setting was set"};
|
||||
};
|
||||
|
||||
MySettings mySettings;
|
||||
|
||||
static GlobalConfig::Register rs(&mySettings);
|
||||
|
||||
static void prim_anotherNull(EvalState& state, const Pos& pos, Value** args,
|
||||
Value& v) {
|
||||
if (mySettings.settingSet)
|
||||
mkNull(v);
|
||||
else
|
||||
mkBool(v, false);
|
||||
}
|
||||
|
||||
static RegisterPrimOp rp("anotherNull", 0, prim_anotherNull);
|
Loading…
Reference in a new issue