diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-01-06 12:43:07 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-01-06 12:43:07 +0100 |
commit | 1dc29df1d384e90d0604e1b21150cfc93b58ff56 (patch) | |
tree | c48f2e772fa5d01eda24f1bd165380f2534dd25a /src/libstore | |
parent | c7866733d7ce2836fbb43de90dd64d17b0d20753 (diff) | |
parent | 0486e87791f0d50f98ccd46c56f32ecc4e1bc79c (diff) |
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/build.cc | 34 | ||||
-rw-r--r-- | src/libstore/globals.cc | 9 | ||||
-rw-r--r-- | src/libstore/globals.hh | 4 |
3 files changed, 29 insertions, 18 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 05c4cb621..f1085cae1 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1514,8 +1514,10 @@ void replaceValidPath(const Path & storePath, const Path tmpPath) Path oldPath = (format("%1%.old-%2%-%3%") % storePath % getpid() % random()).str(); if (pathExists(storePath)) 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); + } deletePath(oldPath); } @@ -1986,7 +1988,7 @@ void DerivationGoal::startBuilder() throw BuildError(format("odd number of tokens in 'exportReferencesGraph': '%1%'") % s); for (Strings::iterator i = ss.begin(); i != ss.end(); ) { 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)) throw Error("invalid file name '%s' in 'exportReferencesGraph'", fileName); @@ -2456,12 +2458,12 @@ void DerivationGoal::initTmpDir() { if (!parsedDrv->getStructuredAttrs()) { StringSet passAsFile = tokenizeString<StringSet>(get(drv->env, "passAsFile").value_or("")); - int fileNr = 0; for (auto & i : drv->env) { if (passAsFile.find(i.first) == passAsFile.end()) { env[i.first] = i.second; } 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; writeFile(p, i.second); chownToBuilder(p); @@ -3566,19 +3568,6 @@ void DerivationGoal::registerOutputs() if (!missingPaths.count(i.second.path)) continue; 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()) { auto r = redirectedOutputs.find(i.second.path); if (r != redirectedOutputs.end()) { @@ -3590,6 +3579,17 @@ void DerivationGoal::registerOutputs() if (buildMode == bmCheck) 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; diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index cec85edca..5f1ae5ab5 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -117,6 +117,15 @@ void Settings::requireExperimentalFeature(const std::string & 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; template<> void BaseSetting<SandboxMode>::set(const std::string & str) diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index ae5a78201..247fba2f8 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -34,6 +34,8 @@ class Settings : public Config { StringSet getDefaultSystemFeatures(); + bool isWSL1(); + public: Settings(); @@ -130,7 +132,7 @@ public: Setting<bool> fsyncMetadata{this, true, "fsync-metadata", "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."}; Setting<bool> syncBeforeRegistering{this, false, "sync-before-registering", |