aboutsummaryrefslogtreecommitdiff
path: root/src/nix-build/nix-build.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix-build/nix-build.cc')
-rw-r--r--src/nix-build/nix-build.cc42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index 426f23905..7eb8c8f6a 100644
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -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
+ );
}
}
@@ -543,6 +573,8 @@ static void main_nix_build(int argc, char * * argv)
restoreProcessContext();
+ logger->stop();
+
execvp(shell->c_str(), argPtrs.data());
throw SysError("executing shell '%s'", *shell);
@@ -601,6 +633,8 @@ static void main_nix_build(int argc, char * * argv)
outPaths.push_back(outputPath);
}
+ logger->stop();
+
for (auto & path : outPaths)
std::cout << store->printStorePath(path) << '\n';
}