aboutsummaryrefslogtreecommitdiff
path: root/src/nix-build/nix-build.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-10-17 17:25:17 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-10-17 17:25:17 +0000
commit2546c63373149dea1511b892a9911768bd770cac (patch)
tree8766f3de7a9cd344e5b9067f83091ae7a28cfd0c /src/nix-build/nix-build.cc
parent7349f257da8278af9aae35544b15c9a204e2a57b (diff)
parentf66bbd8c7bb1472facf8917e58e3cd4f6ddfa1b5 (diff)
Merge commit 'f66bbd8c7bb1472facf8917e58e3cd4f6ddfa1b5' into auto-uid-allocation
Diffstat (limited to 'src/nix-build/nix-build.cc')
-rwxr-xr-xsrc/nix-build/nix-build.cc74
1 files changed, 40 insertions, 34 deletions
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index f77de56ea..a79b1086b 100755
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -67,7 +67,7 @@ std::vector<string> shellwords(const string & s)
return res;
}
-static void _main(int argc, char * * argv)
+static void main_nix_build(int argc, char * * argv)
{
auto dryRun = false;
auto runEnv = std::regex_search(argv[0], std::regex("nix-shell$"));
@@ -98,8 +98,8 @@ static void _main(int argc, char * * argv)
// List of environment variables kept for --pure
std::set<string> keepVars{
- "HOME", "USER", "LOGNAME", "DISPLAY", "PATH", "TERM",
- "IN_NIX_SHELL", "TZ", "PAGER", "NIX_BUILD_SHELL", "SHLVL",
+ "HOME", "USER", "LOGNAME", "DISPLAY", "PATH", "TERM", "IN_NIX_SHELL",
+ "NIX_SHELL_PRESERVE_PROMPT", "TZ", "PAGER", "NIX_BUILD_SHELL", "SHLVL",
"http_proxy", "https_proxy", "ftp_proxy", "all_proxy", "no_proxy"
};
@@ -174,7 +174,7 @@ static void _main(int argc, char * * argv)
else if (*arg == "--run-env") // obsolete
runEnv = true;
- else if (*arg == "--command" || *arg == "--run") {
+ else if (runEnv && (*arg == "--command" || *arg == "--run")) {
if (*arg == "--run")
interactive = false;
envCommand = getArg(*arg, arg, end) + "\nexit";
@@ -192,7 +192,7 @@ static void _main(int argc, char * * argv)
else if (*arg == "--pure") pure = true;
else if (*arg == "--impure") pure = false;
- else if (*arg == "--packages" || *arg == "-p")
+ else if (runEnv && (*arg == "--packages" || *arg == "-p"))
packages = true;
else if (inShebang && *arg == "-i") {
@@ -325,7 +325,7 @@ static void _main(int argc, char * * argv)
auto buildPaths = [&](const std::vector<StorePathWithOutputs> & paths) {
/* Note: we do this even when !printMissing to efficiently
fetch binary cache data. */
- unsigned long long downloadSize, narSize;
+ uint64_t downloadSize, narSize;
StorePathSet willBuild, willSubstitute, unknown;
store->queryMissing(paths,
willBuild, willSubstitute, unknown, downloadSize, narSize);
@@ -446,7 +446,7 @@ static void _main(int argc, char * * argv)
"PATH=%4%:\"$PATH\"; "
"SHELL=%5%; "
"set +e; "
- R"s([ -n "$PS1" ] && PS1='\n\[\033[1;32m\][nix-shell:\w]\$\[\033[0m\] '; )s"
+ R"s([ -n "$PS1" -a -z "$NIX_SHELL_PRESERVE_PROMPT" ] && PS1='\n\[\033[1;32m\][nix-shell:\w]\$\[\033[0m\] '; )s"
"if [ \"$(type -t runHook)\" = function ]; then runHook shellHook; fi; "
"unset NIX_ENFORCE_PURITY; "
"shopt -u nullglob; "
@@ -487,52 +487,58 @@ static void _main(int argc, char * * argv)
std::vector<StorePathWithOutputs> pathsToBuild;
- std::map<Path, Path> drvPrefixes;
- std::map<Path, Path> resultSymlinks;
- std::vector<Path> outPaths;
+ std::map<StorePath, std::pair<size_t, StringSet>> drvMap;
for (auto & drvInfo : drvs) {
- auto drvPath = drvInfo.queryDrvPath();
- auto outPath = drvInfo.queryOutPath();
+ auto drvPath = store->parseStorePath(drvInfo.queryDrvPath());
auto outputName = drvInfo.queryOutputName();
if (outputName == "")
- throw Error("derivation '%s' lacks an 'outputName' attribute", drvPath);
+ throw Error("derivation '%s' lacks an 'outputName' attribute", store->printStorePath(drvPath));
- pathsToBuild.push_back({store->parseStorePath(drvPath), {outputName}});
+ pathsToBuild.push_back({drvPath, {outputName}});
- std::string drvPrefix;
- auto i = drvPrefixes.find(drvPath);
- if (i != drvPrefixes.end())
- drvPrefix = i->second;
+ auto i = drvMap.find(drvPath);
+ if (i != drvMap.end())
+ i->second.second.insert(outputName);
else {
- drvPrefix = outLink;
- if (drvPrefixes.size())
- drvPrefix += fmt("-%d", drvPrefixes.size() + 1);
- drvPrefixes[drvPath] = drvPrefix;
+ drvMap[drvPath] = {drvMap.size(), {outputName}};
}
-
- std::string symlink = drvPrefix;
- if (outputName != "out") symlink += "-" + outputName;
-
- resultSymlinks[symlink] = outPath;
- outPaths.push_back(outPath);
}
buildPaths(pathsToBuild);
if (dryRun) return;
- for (auto & symlink : resultSymlinks)
- if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
- store2->addPermRoot(store->parseStorePath(symlink.second), absPath(symlink.first), true);
+ std::vector<StorePath> outPaths;
+
+ for (auto & [drvPath, info] : drvMap) {
+ auto & [counter, wantedOutputs] = info;
+ std::string drvPrefix = outLink;
+ if (counter)
+ drvPrefix += fmt("-%d", counter + 1);
+
+ auto builtOutputs = store->queryDerivationOutputMap(drvPath);
+
+ for (auto & outputName : wantedOutputs) {
+ auto outputPath = builtOutputs.at(outputName);
+
+ if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>()) {
+ std::string symlink = drvPrefix;
+ if (outputName != "out") symlink += "-" + outputName;
+ store2->addPermRoot(outputPath, absPath(symlink));
+ }
+
+ outPaths.push_back(outputPath);
+ }
+ }
logger->stop();
for (auto & path : outPaths)
- std::cout << path << '\n';
+ std::cout << store->printStorePath(path) << '\n';
}
}
-static RegisterLegacyCommand s1("nix-build", _main);
-static RegisterLegacyCommand s2("nix-shell", _main);
+static RegisterLegacyCommand r_nix_build("nix-build", main_nix_build);
+static RegisterLegacyCommand r_nix_shell("nix-shell", main_nix_build);