mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 06:42:28 +00:00
Initialize plugins after handling initial command line flags
This is technically a breaking change, since attempting to set plugin files after the first non-flag argument will now throw an error. This is acceptable given the relative lack of stability in a plugin interface and the need to tie the knot somewhere once plugins can actually define new subcommands.
This commit is contained in:
parent
ec3497c1d6
commit
98d1b64400
7
doc/manual/src/release-notes/rl-2.4.md
Normal file
7
doc/manual/src/release-notes/rl-2.4.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Release 2.4 (202X-XX-XX)
|
||||
|
||||
- It is now an error to modify the `plugin-files` setting via a
|
||||
command-line flag that appears after the first non-flag argument
|
||||
to any command, including a subcommand to `nix`. For example,
|
||||
`nix-instantiate default.nix --plugin-files ""` must now become
|
||||
`nix-instantiate --plugin-files "" default.nix`.
|
@ -53,6 +53,9 @@ static int main_build_remote(int argc, char * * argv)
|
||||
unsetenv("DISPLAY");
|
||||
unsetenv("SSH_ASKPASS");
|
||||
|
||||
/* If we ever use the common args framework, make sure to
|
||||
remove initPlugins below and initialize settings first.
|
||||
*/
|
||||
if (argc != 2)
|
||||
throw UsageError("called without required arguments");
|
||||
|
||||
|
@ -79,4 +79,11 @@ MixCommonArgs::MixCommonArgs(const string & programName)
|
||||
hiddenCategories.insert(cat);
|
||||
}
|
||||
|
||||
void MixCommonArgs::initialFlagsProcessed()
|
||||
{
|
||||
initPlugins();
|
||||
pluginsInited();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,10 +7,14 @@ namespace nix {
|
||||
//static constexpr auto commonArgsCategory = "Miscellaneous common options";
|
||||
static constexpr auto loggingCategory = "Logging-related options";
|
||||
|
||||
struct MixCommonArgs : virtual Args
|
||||
class MixCommonArgs : public virtual Args
|
||||
{
|
||||
void initialFlagsProcessed() override;
|
||||
public:
|
||||
string programName;
|
||||
MixCommonArgs(const string & programName);
|
||||
protected:
|
||||
virtual void pluginsInited() {}
|
||||
};
|
||||
|
||||
struct MixDryRun : virtual Args
|
||||
|
@ -253,6 +253,7 @@ void PluginFilesSetting::set(const std::string & str, bool append)
|
||||
|
||||
void initPlugins()
|
||||
{
|
||||
assert(!settings.pluginFiles.pluginsLoaded);
|
||||
for (const auto & pluginFile : settings.pluginFiles.get()) {
|
||||
Paths pluginFiles;
|
||||
try {
|
||||
|
@ -60,6 +60,7 @@ void Args::parseCmdline(const Strings & _cmdline)
|
||||
verbosity = lvlError;
|
||||
}
|
||||
|
||||
bool argsSeen = false;
|
||||
for (auto pos = cmdline.begin(); pos != cmdline.end(); ) {
|
||||
|
||||
auto arg = *pos;
|
||||
@ -88,6 +89,10 @@ void Args::parseCmdline(const Strings & _cmdline)
|
||||
throw UsageError("unrecognised flag '%1%'", arg);
|
||||
}
|
||||
else {
|
||||
if (!argsSeen) {
|
||||
argsSeen = true;
|
||||
initialFlagsProcessed();
|
||||
}
|
||||
pos = rewriteArgs(cmdline, pos);
|
||||
pendingArgs.push_back(*pos++);
|
||||
if (processArgs(pendingArgs, false))
|
||||
@ -96,6 +101,9 @@ void Args::parseCmdline(const Strings & _cmdline)
|
||||
}
|
||||
|
||||
processArgs(pendingArgs, true);
|
||||
|
||||
if (!argsSeen)
|
||||
initialFlagsProcessed();
|
||||
}
|
||||
|
||||
bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
|
||||
|
@ -132,6 +132,10 @@ protected:
|
||||
|
||||
std::set<std::string> hiddenCategories;
|
||||
|
||||
/* Called after all command line flags before the first non-flag
|
||||
argument (if any) have been processed. */
|
||||
virtual void initialFlagsProcessed() {}
|
||||
|
||||
public:
|
||||
|
||||
void addFlag(Flag && flag);
|
||||
|
@ -240,8 +240,6 @@ static void main_nix_build(int argc, char * * argv)
|
||||
|
||||
myArgs.parseCmdline(args);
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (packages && fromArgs)
|
||||
throw UsageError("'-p' and '-E' are mutually exclusive");
|
||||
|
||||
|
@ -196,8 +196,6 @@ static int main_nix_channel(int argc, char ** argv)
|
||||
return true;
|
||||
});
|
||||
|
||||
initPlugins();
|
||||
|
||||
switch (cmd) {
|
||||
case cNone:
|
||||
throw UsageError("no command specified");
|
||||
|
@ -74,8 +74,6 @@ static int main_nix_collect_garbage(int argc, char * * argv)
|
||||
return true;
|
||||
});
|
||||
|
||||
initPlugins();
|
||||
|
||||
auto profilesDir = settings.nixStateDir + "/profiles";
|
||||
if (removeOld) removeOldGenerations(profilesDir);
|
||||
|
||||
|
@ -43,8 +43,6 @@ static int main_nix_copy_closure(int argc, char ** argv)
|
||||
return true;
|
||||
});
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (sshHost.empty())
|
||||
throw UsageError("no host name specified");
|
||||
|
||||
|
@ -1420,8 +1420,6 @@ static int main_nix_env(int argc, char * * argv)
|
||||
|
||||
myArgs.parseCmdline(argvToStrings(argc, argv));
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (!op) throw UsageError("no operation specified");
|
||||
|
||||
auto store = openStore();
|
||||
|
@ -149,8 +149,6 @@ static int main_nix_instantiate(int argc, char * * argv)
|
||||
|
||||
myArgs.parseCmdline(argvToStrings(argc, argv));
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (evalOnly && !wantsReadWrite)
|
||||
settings.readOnlyMode = true;
|
||||
|
||||
|
@ -1067,8 +1067,6 @@ static int main_nix_store(int argc, char * * argv)
|
||||
return true;
|
||||
});
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (!op) throw UsageError("no operation specified");
|
||||
|
||||
if (op != opDump && op != opRestore) /* !!! hack */
|
||||
|
@ -326,8 +326,6 @@ static int main_nix_daemon(int argc, char * * argv)
|
||||
return true;
|
||||
});
|
||||
|
||||
initPlugins();
|
||||
|
||||
runDaemon(stdio);
|
||||
|
||||
return 0;
|
||||
|
@ -283,8 +283,6 @@ void mainWrapped(int argc, char * * argv)
|
||||
|
||||
if (completions) return;
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (args.showVersion) {
|
||||
printVersion(programName);
|
||||
return;
|
||||
|
@ -171,8 +171,6 @@ static int main_nix_prefetch_url(int argc, char * * argv)
|
||||
|
||||
myArgs.parseCmdline(argvToStrings(argc, argv));
|
||||
|
||||
initPlugins();
|
||||
|
||||
if (args.size() > 2)
|
||||
throw UsageError("too many arguments");
|
||||
|
||||
|
@ -2,6 +2,6 @@ source common.sh
|
||||
|
||||
set -o pipefail
|
||||
|
||||
res=$(nix eval --expr builtins.anotherNull --option setting-set true --option plugin-files $PWD/plugins/libplugintest*)
|
||||
res=$(nix --option setting-set true --option plugin-files $PWD/plugins/libplugintest* eval --expr builtins.anotherNull)
|
||||
|
||||
[ "$res"x = "nullx" ]
|
||||
|
Loading…
Reference in New Issue
Block a user