forked from lix-project/lix
Merge pull request #6664 from Ma27/innixshell-backwards-compat
nix-shell: restore backwards-compat with old nixpkgs
This commit is contained in:
commit
d63cd77549
|
@ -257,11 +257,12 @@ static void main_nix_build(int argc, char * * argv)
|
|||
|
||||
auto autoArgs = myArgs.getAutoArgs(*state);
|
||||
|
||||
auto autoArgsWithInNixShell = autoArgs;
|
||||
if (runEnv) {
|
||||
auto newArgs = state->buildBindings(autoArgs->size() + 1);
|
||||
auto newArgs = state->buildBindings(autoArgsWithInNixShell->size() + 1);
|
||||
newArgs.alloc("inNixShell").mkBool(true);
|
||||
for (auto & i : *autoArgs) newArgs.insert(i);
|
||||
autoArgs = newArgs.finish();
|
||||
autoArgsWithInNixShell = newArgs.finish();
|
||||
}
|
||||
|
||||
if (packages) {
|
||||
|
@ -316,10 +317,39 @@ static void main_nix_build(int argc, char * * argv)
|
|||
Value vRoot;
|
||||
state->eval(e, vRoot);
|
||||
|
||||
std::function<bool(const Value & v)> takesNixShellAttr;
|
||||
takesNixShellAttr = [&](const Value & v) {
|
||||
if (!runEnv) {
|
||||
return false;
|
||||
}
|
||||
bool add = false;
|
||||
if (v.type() == nFunction && v.lambda.fun->hasFormals()) {
|
||||
for (auto & i : v.lambda.fun->formals->formals) {
|
||||
if (state->symbols[i.name] == "inNixShell") {
|
||||
add = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return add;
|
||||
};
|
||||
|
||||
for (auto & i : attrPaths) {
|
||||
Value & v(*findAlongAttrPath(*state, i, *autoArgs, vRoot).first);
|
||||
Value & v(*findAlongAttrPath(
|
||||
*state,
|
||||
i,
|
||||
takesNixShellAttr(vRoot) ? *autoArgsWithInNixShell : *autoArgs,
|
||||
vRoot
|
||||
).first);
|
||||
state->forceValue(v, [&]() { return v.determinePos(noPos); });
|
||||
getDerivations(*state, v, "", *autoArgs, drvs, false);
|
||||
getDerivations(
|
||||
*state,
|
||||
v,
|
||||
"",
|
||||
takesNixShellAttr(v) ? *autoArgsWithInNixShell : *autoArgs,
|
||||
drvs,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
{ ... }@args: import ./shell.nix (args // { contentAddressed = true; })
|
||||
{ inNixShell ? false, ... }@args: import ./shell.nix (args // { contentAddressed = true; })
|
||||
|
|
|
@ -102,3 +102,11 @@ source <(nix print-dev-env -f "$shellDotNix" shellDrv)
|
|||
[[ ${arr2[1]} = $'\n' ]]
|
||||
[[ ${arr2[2]} = $'x\ny' ]]
|
||||
[[ $(fun) = blabla ]]
|
||||
|
||||
# Test nix-shell with ellipsis and no `inNixShell` argument (for backwards compat with old nixpkgs)
|
||||
cat >$TEST_ROOT/shell-ellipsis.nix <<EOF
|
||||
{ system ? "x86_64-linux", ... }@args:
|
||||
assert (!(args ? inNixShell));
|
||||
(import $shellDotNix { }).shellDrv
|
||||
EOF
|
||||
nix-shell $TEST_ROOT/shell-ellipsis.nix --run "true"
|
||||
|
|
Loading…
Reference in a new issue