1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-08 02:43:54 +02:00

Add opt-out: nix-shell-shebang-arguments-relative-to-script

This commit is contained in:
Robert Hensing 2024-07-07 00:55:33 +02:00
parent 4c59d6e9f5
commit 63262e78c7
5 changed files with 22 additions and 3 deletions

View file

@ -202,7 +202,7 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
auto v = state.allocValue();
std::visit(overloaded {
[&](const AutoArgExpr & arg) {
state.mkThunk_(*v, state.parseExprFromString(arg.expr, true ? state.rootPath(absPath(getCommandBaseDir())) : state.rootPath(".")));
state.mkThunk_(*v, state.parseExprFromString(arg.expr, compatibilitySettings.nixShellShebangArgumentsRelativeToScript ? state.rootPath(absPath(getCommandBaseDir())) : state.rootPath(".")));
},
[&](const AutoArgString & arg) {
v->mkString(arg.s);

View file

@ -14,6 +14,15 @@ struct CompatibilitySettings : public Config
You may set this to `false` to revert to the Nix 2.3 behavior.
)"};
Setting<bool> nixShellShebangArgumentsRelativeToScript{
this, true, "nix-shell-shebang-arguments-relative-to-script", R"(
Before Nix 2.24, the arguments in a `nix-shell` shebang - as well as `--arg` - were relative to working directory.
Since Nix 2.24, the arguments are relative to the [base directory](@docroot@/glossary.md#gloss-base-directory) defined as the script's directory.
You may set this to `false` to revert to the Nix 2.3 behavior.
)"};
};
};

View file

@ -293,7 +293,7 @@ static void main_nix_build(int argc, char * * argv)
state->repair = myArgs.repair;
if (myArgs.repair) buildMode = bmRepair;
if (inShebang) {
if (inShebang && compatibilitySettings.nixShellShebangArgumentsRelativeToScript) {
myArgs.setBaseDir(absPath(dirOf(script)));
}
auto autoArgs = myArgs.getAutoArgs(*state);
@ -345,7 +345,7 @@ static void main_nix_build(int argc, char * * argv)
if (fromArgs)
exprs.push_back(state->parseExprFromString(
std::move(i),
inShebang ? lookupFileArg(*state, baseDir) : state->rootPath(".")
(inShebang && compatibilitySettings.nixShellShebangArgumentsRelativeToScript) ? lookupFileArg(*state, baseDir) : state->rootPath(".")
));
else {
auto absolute = i;