Merge remote-tracking branch 'origin/master' into flakes

This commit is contained in:
Eelco Dolstra 2020-01-06 12:43:07 +01:00
commit 1dc29df1d3
9 changed files with 52 additions and 35 deletions

View file

@ -102,7 +102,7 @@ for i in $(cd "$self/store" >/dev/null && echo ./*); do
rm -rf "$i_tmp" rm -rf "$i_tmp"
fi fi
if ! [ -e "$dest/store/$i" ]; then if ! [ -e "$dest/store/$i" ]; then
cp -Rp "$self/store/$i" "$i_tmp" cp -RPp "$self/store/$i" "$i_tmp"
chmod -R a-w "$i_tmp" chmod -R a-w "$i_tmp"
chmod +w "$i_tmp" chmod +w "$i_tmp"
mv "$i_tmp" "$dest/store/$i" mv "$i_tmp" "$dest/store/$i"

View file

@ -56,7 +56,7 @@ fi
unpack=$tmpDir/unpack unpack=$tmpDir/unpack
mkdir -p "$unpack" mkdir -p "$unpack"
tar -xf "$tarball" -C "$unpack" || oops "failed to unpack '$url'" tar -xJf "$tarball" -C "$unpack" || oops "failed to unpack '$url'"
script=$(echo "$unpack"/*/install) script=$(echo "$unpack"/*/install)

View file

@ -1146,9 +1146,7 @@ void EvalState::callPrimOp(Value & fun, Value & arg, Value & v, const Pos & pos)
void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & pos) void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & pos)
{ {
std::unique_ptr<FunctionCallTrace> trace; auto trace = evalSettings.traceFunctionCalls ? std::make_unique<FunctionCallTrace>(pos) : nullptr;
if (evalSettings.traceFunctionCalls)
trace = std::make_unique<FunctionCallTrace>(pos);
forceValue(fun, pos); forceValue(fun, pos);

View file

@ -0,0 +1,17 @@
#include "function-trace.hh"
namespace nix {
FunctionCallTrace::FunctionCallTrace(const Pos & pos) : pos(pos) {
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
printMsg(lvlInfo, "function-trace entered %1% at %2%", pos, ns.count());
}
FunctionCallTrace::~FunctionCallTrace() {
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
printMsg(lvlInfo, "function-trace exited %1% at %2%", pos, ns.count());
}
}

View file

@ -9,17 +9,7 @@ namespace nix {
struct FunctionCallTrace struct FunctionCallTrace
{ {
const Pos & pos; const Pos & pos;
FunctionCallTrace(const Pos & pos);
FunctionCallTrace(const Pos & pos) : pos(pos) { ~FunctionCallTrace();
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
printMsg(lvlInfo, "function-trace entered %1% at %2%", pos, ns.count());
}
~FunctionCallTrace() {
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
printMsg(lvlInfo, "function-trace exited %1% at %2%", pos, ns.count());
}
}; };
} }

View file

@ -1514,8 +1514,10 @@ void replaceValidPath(const Path & storePath, const Path tmpPath)
Path oldPath = (format("%1%.old-%2%-%3%") % storePath % getpid() % random()).str(); Path oldPath = (format("%1%.old-%2%-%3%") % storePath % getpid() % random()).str();
if (pathExists(storePath)) if (pathExists(storePath))
rename(storePath.c_str(), oldPath.c_str()); rename(storePath.c_str(), oldPath.c_str());
if (rename(tmpPath.c_str(), storePath.c_str()) == -1) if (rename(tmpPath.c_str(), storePath.c_str()) == -1) {
rename(oldPath.c_str(), storePath.c_str()); // attempt to recover
throw SysError("moving '%s' to '%s'", tmpPath, storePath); throw SysError("moving '%s' to '%s'", tmpPath, storePath);
}
deletePath(oldPath); deletePath(oldPath);
} }
@ -1986,7 +1988,7 @@ void DerivationGoal::startBuilder()
throw BuildError(format("odd number of tokens in 'exportReferencesGraph': '%1%'") % s); throw BuildError(format("odd number of tokens in 'exportReferencesGraph': '%1%'") % s);
for (Strings::iterator i = ss.begin(); i != ss.end(); ) { for (Strings::iterator i = ss.begin(); i != ss.end(); ) {
string fileName = *i++; string fileName = *i++;
static std::regex regex("[A-Za-z_][A-Za-z0-9_.]*"); static std::regex regex("[A-Za-z_][A-Za-z0-9_.-]*");
if (!std::regex_match(fileName, regex)) if (!std::regex_match(fileName, regex))
throw Error("invalid file name '%s' in 'exportReferencesGraph'", fileName); throw Error("invalid file name '%s' in 'exportReferencesGraph'", fileName);
@ -2456,12 +2458,12 @@ void DerivationGoal::initTmpDir() {
if (!parsedDrv->getStructuredAttrs()) { if (!parsedDrv->getStructuredAttrs()) {
StringSet passAsFile = tokenizeString<StringSet>(get(drv->env, "passAsFile").value_or("")); StringSet passAsFile = tokenizeString<StringSet>(get(drv->env, "passAsFile").value_or(""));
int fileNr = 0;
for (auto & i : drv->env) { for (auto & i : drv->env) {
if (passAsFile.find(i.first) == passAsFile.end()) { if (passAsFile.find(i.first) == passAsFile.end()) {
env[i.first] = i.second; env[i.first] = i.second;
} else { } else {
string fn = ".attr-" + std::to_string(fileNr++); auto hash = hashString(htSHA256, i.first);
string fn = ".attr-" + hash.to_string(Base32, false);
Path p = tmpDir + "/" + fn; Path p = tmpDir + "/" + fn;
writeFile(p, i.second); writeFile(p, i.second);
chownToBuilder(p); chownToBuilder(p);
@ -3566,19 +3568,6 @@ void DerivationGoal::registerOutputs()
if (!missingPaths.count(i.second.path)) continue; if (!missingPaths.count(i.second.path)) continue;
Path actualPath = path; Path actualPath = path;
if (useChroot) {
actualPath = chrootRootDir + path;
if (pathExists(actualPath)) {
/* Move output paths from the chroot to the Nix store. */
if (buildMode == bmRepair)
replaceValidPath(path, actualPath);
else
if (buildMode != bmCheck && rename(actualPath.c_str(), worker.store.toRealPath(path).c_str()) == -1)
throw SysError(format("moving build output '%1%' from the sandbox to the Nix store") % path);
}
if (buildMode != bmCheck) actualPath = worker.store.toRealPath(path);
}
if (needsHashRewrite()) { if (needsHashRewrite()) {
auto r = redirectedOutputs.find(i.second.path); auto r = redirectedOutputs.find(i.second.path);
if (r != redirectedOutputs.end()) { if (r != redirectedOutputs.end()) {
@ -3590,6 +3579,17 @@ void DerivationGoal::registerOutputs()
if (buildMode == bmCheck) if (buildMode == bmCheck)
actualPath = redirected; actualPath = redirected;
} }
} else if (useChroot) {
actualPath = chrootRootDir + path;
if (pathExists(actualPath)) {
/* Move output paths from the chroot to the Nix store. */
if (buildMode == bmRepair)
replaceValidPath(path, actualPath);
else
if (buildMode != bmCheck && rename(actualPath.c_str(), worker.store.toRealPath(path).c_str()) == -1)
throw SysError(format("moving build output '%1%' from the sandbox to the Nix store") % path);
}
if (buildMode != bmCheck) actualPath = worker.store.toRealPath(path);
} }
struct stat st; struct stat st;

View file

@ -117,6 +117,15 @@ void Settings::requireExperimentalFeature(const std::string & name)
throw Error("experimental Nix feature '%s' is disabled", name); throw Error("experimental Nix feature '%s' is disabled", name);
} }
bool Settings::isWSL1()
{
struct utsname utsbuf;
uname(&utsbuf);
// WSL1 uses -Microsoft suffix
// WSL2 uses -microsoft-standard suffix
return hasSuffix(utsbuf.release, "-Microsoft");
}
const string nixVersion = PACKAGE_VERSION; const string nixVersion = PACKAGE_VERSION;
template<> void BaseSetting<SandboxMode>::set(const std::string & str) template<> void BaseSetting<SandboxMode>::set(const std::string & str)

View file

@ -34,6 +34,8 @@ class Settings : public Config {
StringSet getDefaultSystemFeatures(); StringSet getDefaultSystemFeatures();
bool isWSL1();
public: public:
Settings(); Settings();
@ -130,7 +132,7 @@ public:
Setting<bool> fsyncMetadata{this, true, "fsync-metadata", Setting<bool> fsyncMetadata{this, true, "fsync-metadata",
"Whether SQLite should use fsync()."}; "Whether SQLite should use fsync()."};
Setting<bool> useSQLiteWAL{this, true, "use-sqlite-wal", Setting<bool> useSQLiteWAL{this, !isWSL1(), "use-sqlite-wal",
"Whether SQLite should use WAL mode."}; "Whether SQLite should use WAL mode."};
Setting<bool> syncBeforeRegistering{this, false, "sync-before-registering", Setting<bool> syncBeforeRegistering{this, false, "sync-before-registering",

View file

@ -10,6 +10,7 @@ mkDerivation {
passAsFile = [ \"foo\" ]; passAsFile = [ \"foo\" ];
foo = [ \"xyzzy\" ]; foo = [ \"xyzzy\" ];
builder = builtins.toFile \"builder.sh\" '' builder = builtins.toFile \"builder.sh\" ''
[ \"\$(basename \$fooPath)\" = .attr-1bp7cri8hplaz6hbz0v4f0nl44rl84q1sg25kgwqzipzd1mv89ic ]
[ \"\$(cat \$fooPath)\" = xyzzy ] [ \"\$(cat \$fooPath)\" = xyzzy ]
touch \$out touch \$out
''; '';