aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Burdette <bburdette@protonmail.com>2022-04-15 14:49:08 -0600
committerBen Burdette <bburdette@protonmail.com>2022-04-15 14:49:08 -0600
commit93b8d315087921b0a024bf87555ac6c3bca6882d (patch)
tree6d1215c6ed2840a71aee94bae892b1fd219bf17c /src
parent8b197c492e4e2878eb58bb2994fb8d7f8044bf90 (diff)
parentb135de2b5f08aa8b549d69371823235124ef04a1 (diff)
Merge branch 'master' into debug-exploratory-PR
Diffstat (limited to 'src')
-rw-r--r--src/libcmd/command.hh5
-rw-r--r--src/libcmd/installables.cc23
-rw-r--r--src/libfetchers/fetchers.cc15
-rw-r--r--src/libfetchers/git.cc12
-rw-r--r--src/libfetchers/mercurial.cc17
-rw-r--r--src/libstore/build-result.hh2
-rw-r--r--src/libstore/build/derivation-goal.cc3
-rw-r--r--src/libstore/build/local-derivation-goal.cc3
-rw-r--r--src/libstore/filetransfer.hh2
-rw-r--r--src/libstore/sqlite.cc1
-rw-r--r--src/libutil/error.cc3
-rw-r--r--src/libutil/error.hh6
-rw-r--r--src/libutil/experimental-features.hh4
-rw-r--r--src/libutil/hash.cc2
-rw-r--r--src/libutil/hash.hh2
-rw-r--r--src/libutil/serialise.cc5
-rw-r--r--src/libutil/tests/url.cc4
-rw-r--r--src/libutil/url-parts.hh2
-rw-r--r--src/nix/eval.cc2
19 files changed, 71 insertions, 42 deletions
diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh
index 9247d401e..826531a18 100644
--- a/src/libcmd/command.hh
+++ b/src/libcmd/command.hh
@@ -87,11 +87,12 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
{
std::optional<Path> file;
std::optional<std::string> expr;
+ bool readOnlyMode = false;
// FIXME: move this; not all commands (e.g. 'nix run') use it.
OperateOn operateOn = OperateOn::Output;
- SourceExprCommand();
+ SourceExprCommand(bool supportReadOnlyMode = false);
std::vector<std::shared_ptr<Installable>> parseInstallables(
ref<Store> store, std::vector<std::string> ss);
@@ -130,7 +131,7 @@ struct InstallableCommand : virtual Args, SourceExprCommand
{
std::shared_ptr<Installable> installable;
- InstallableCommand();
+ InstallableCommand(bool supportReadOnlyMode = false);
void prepare() override;
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
index 955bbe6fb..4e7262432 100644
--- a/src/libcmd/installables.cc
+++ b/src/libcmd/installables.cc
@@ -1,3 +1,4 @@
+#include "globals.hh"
#include "installables.hh"
#include "command.hh"
#include "attr-path.hh"
@@ -129,7 +130,7 @@ MixFlakeOptions::MixFlakeOptions()
});
}
-SourceExprCommand::SourceExprCommand()
+SourceExprCommand::SourceExprCommand(bool supportReadOnlyMode)
{
addFlag({
.longName = "file",
@@ -157,6 +158,17 @@ SourceExprCommand::SourceExprCommand()
.category = installablesCategory,
.handler = {&operateOn, OperateOn::Derivation},
});
+
+ if (supportReadOnlyMode) {
+ addFlag({
+ .longName = "read-only",
+ .description =
+ "Do not instantiate each evaluated derivation. "
+ "This improves performance, but can cause errors when accessing "
+ "store paths of derivations during evaluation.",
+ .handler = {&readOnlyMode, true},
+ });
+ }
}
Strings SourceExprCommand::getDefaultFlakeAttrPaths()
@@ -687,6 +699,10 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
{
std::vector<std::shared_ptr<Installable>> result;
+ if (readOnlyMode) {
+ settings.readOnlyMode = true;
+ }
+
if (file || expr) {
if (file && expr)
throw UsageError("'--file' and '--expr' are exclusive");
@@ -954,7 +970,7 @@ InstallablesCommand::InstallablesCommand()
void InstallablesCommand::prepare()
{
if (_installables.empty() && useDefaultInstallables())
- // FIXME: commands like "nix install" should not have a
+ // FIXME: commands like "nix profile install" should not have a
// default, probably.
_installables.push_back(".");
installables = parseInstallables(getStore(), _installables);
@@ -970,7 +986,8 @@ std::optional<FlakeRef> InstallablesCommand::getFlakeRefForCompletion()
return parseFlakeRef(_installables.front(), absPath("."));
}
-InstallableCommand::InstallableCommand()
+InstallableCommand::InstallableCommand(bool supportReadOnlyMode)
+ : SourceExprCommand(supportReadOnlyMode)
{
expectArgs({
.label = "installable",
diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc
index 976f40d3b..6957d2da4 100644
--- a/src/libfetchers/fetchers.cc
+++ b/src/libfetchers/fetchers.cc
@@ -238,9 +238,18 @@ std::optional<std::string> Input::getRef() const
std::optional<Hash> Input::getRev() const
{
- if (auto s = maybeGetStrAttr(attrs, "rev"))
- return Hash::parseAny(*s, htSHA1);
- return {};
+ std::optional<Hash> hash = {};
+
+ if (auto s = maybeGetStrAttr(attrs, "rev")) {
+ try {
+ hash = Hash::parseAnyPrefixed(*s);
+ } catch (BadHash &e) {
+ // Default to sha1 for backwards compatibility with existing flakes
+ hash = Hash::parseAny(*s, htSHA1);
+ }
+ }
+
+ return hash;
}
std::optional<uint64_t> Input::getRevCount() const
diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc
index f8433bc28..34b1342a0 100644
--- a/src/libfetchers/git.cc
+++ b/src/libfetchers/git.cc
@@ -28,9 +28,7 @@ static std::string readHead(const Path & path)
static bool isNotDotGitDirectory(const Path & path)
{
- static const std::regex gitDirRegex("^(?:.*/)?\\.git$");
-
- return not std::regex_match(path, gitDirRegex);
+ return baseNameOf(path) != ".git";
}
struct GitInputScheme : InputScheme
@@ -189,8 +187,16 @@ struct GitInputScheme : InputScheme
if (submodules) cacheType += "-submodules";
if (allRefs) cacheType += "-all-refs";
+ auto checkHashType = [&](const std::optional<Hash> & hash)
+ {
+ if (hash.has_value() && !(hash->type == htSHA1 || hash->type == htSHA256))
+ throw Error("Hash '%s' is not supported by Git. Supported types are sha1 and sha256.", hash->to_string(Base16, true));
+ };
+
auto getLockedAttrs = [&]()
{
+ checkHashType(input.getRev());
+
return Attrs({
{"type", cacheType},
{"name", name},
diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc
index 8b82e9daa..1beb8b944 100644
--- a/src/libfetchers/mercurial.cc
+++ b/src/libfetchers/mercurial.cc
@@ -178,9 +178,11 @@ struct MercurialInputScheme : InputScheme
auto files = tokenizeString<std::set<std::string>>(
runHg({ "status", "-R", actualUrl, "--clean", "--modified", "--added", "--no-status", "--print0" }), "\0"s);
+ Path actualPath(absPath(actualUrl));
+
PathFilter filter = [&](const Path & p) -> bool {
- assert(hasPrefix(p, actualUrl));
- std::string file(p, actualUrl.size() + 1);
+ assert(hasPrefix(p, actualPath));
+ std::string file(p, actualPath.size() + 1);
auto st = lstat(p);
@@ -193,7 +195,7 @@ struct MercurialInputScheme : InputScheme
return files.count(file);
};
- auto storePath = store->addToStore(input.getName(), actualUrl, FileIngestionMethod::Recursive, htSHA256, filter);
+ auto storePath = store->addToStore(input.getName(), actualPath, FileIngestionMethod::Recursive, htSHA256, filter);
return {std::move(storePath), input};
}
@@ -201,8 +203,17 @@ struct MercurialInputScheme : InputScheme
if (!input.getRef()) input.attrs.insert_or_assign("ref", "default");
+ auto checkHashType = [&](const std::optional<Hash> & hash)
+ {
+ if (hash.has_value() && hash->type != htSHA1)
+ throw Error("Hash '%s' is not supported by Mercurial. Only sha1 is supported.", hash->to_string(Base16, true));
+ };
+
+
auto getLockedAttrs = [&]()
{
+ checkHashType(input.getRev());
+
return Attrs({
{"type", "hg"},
{"name", name},
diff --git a/src/libstore/build-result.hh b/src/libstore/build-result.hh
index 7f9bcce6d..24fb1f763 100644
--- a/src/libstore/build-result.hh
+++ b/src/libstore/build-result.hh
@@ -31,6 +31,8 @@ struct BuildResult
ResolvesToAlreadyValid,
NoSubstituters,
} status = MiscFailure;
+
+ // FIXME: include entire ErrorInfo object.
std::string errorMsg;
std::string toString() const {
diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc
index 6582497bd..53f212c1d 100644
--- a/src/libstore/build/derivation-goal.cc
+++ b/src/libstore/build/derivation-goal.cc
@@ -1371,8 +1371,7 @@ void DerivationGoal::done(
{
buildResult.status = status;
if (ex)
- // FIXME: strip: "error: "
- buildResult.errorMsg = ex->what();
+ buildResult.errorMsg = fmt("%s", normaltxt(ex->info().msg));
if (buildResult.status == BuildResult::TimedOut)
worker.timedOut = true;
if (buildResult.status == BuildResult::PermanentFailure)
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
index 40ef706a6..4c91fa4fb 100644
--- a/src/libstore/build/local-derivation-goal.cc
+++ b/src/libstore/build/local-derivation-goal.cc
@@ -704,6 +704,9 @@ void LocalDerivationGoal::startBuilder()
/* Run the builder. */
printMsg(lvlChatty, "executing builder '%1%'", drv->builder);
+ printMsg(lvlChatty, "using builder args '%1%'", concatStringsSep(" ", drv->args));
+ for (auto & i : drv->env)
+ printMsg(lvlVomit, "setting builder env variable '%1%'='%2%'", i.first, i.second);
/* Create the log file. */
Path logFile = openLogFile();
diff --git a/src/libstore/filetransfer.hh b/src/libstore/filetransfer.hh
index ca61e3937..1ad96bc10 100644
--- a/src/libstore/filetransfer.hh
+++ b/src/libstore/filetransfer.hh
@@ -123,8 +123,6 @@ public:
template<typename... Args>
FileTransferError(FileTransfer::Error error, std::optional<std::string> response, const Args & ... args);
-
- virtual const char* sname() const override { return "FileTransferError"; }
};
bool isUri(std::string_view s);
diff --git a/src/libstore/sqlite.cc b/src/libstore/sqlite.cc
index e6ecadd7f..1d82b4ab1 100644
--- a/src/libstore/sqlite.cc
+++ b/src/libstore/sqlite.cc
@@ -215,7 +215,6 @@ void handleSQLiteBusy(const SQLiteBusy & e)
if (now > lastWarned + 10) {
lastWarned = now;
logWarning({
- .name = "Sqlite busy",
.msg = hintfmt(e.what())
});
}
diff --git a/src/libutil/error.cc b/src/libutil/error.cc
index 02bc5caa5..9172f67a6 100644
--- a/src/libutil/error.cc
+++ b/src/libutil/error.cc
@@ -21,12 +21,9 @@ const std::string & BaseError::calcWhat() const
if (what_.has_value())
return *what_;
else {
- err.name = sname();
-
std::ostringstream oss;
showErrorInfo(oss, err, loggerSettings.showTrace);
what_ = oss.str();
-
return *what_;
}
}
diff --git a/src/libutil/error.hh b/src/libutil/error.hh
index d17575f47..e31311c80 100644
--- a/src/libutil/error.hh
+++ b/src/libutil/error.hh
@@ -118,7 +118,6 @@ struct Trace {
struct ErrorInfo {
Verbosity level;
- std::string name; // FIXME: rename
hintformat msg;
std::optional<ErrPos> errPos;
std::list<Trace> traces;
@@ -171,8 +170,6 @@ public:
: err(e)
{ }
- virtual const char* sname() const { return "BaseError"; }
-
#ifdef EXCEPTION_NEEDS_THROW_SPEC
~BaseError() throw () { };
const char * what() const throw () { return calcWhat().c_str(); }
@@ -199,7 +196,6 @@ public:
{ \
public: \
using superClass::superClass; \
- virtual const char* sname() const override { return #newClass; } \
}
MakeError(Error, BaseError);
@@ -219,8 +215,6 @@ public:
auto hf = hintfmt(args...);
err.msg = hintfmt("%1%: %2%", normaltxt(hf.str()), strerror(errNo));
}
-
- virtual const char* sname() const override { return "SysError"; }
};
}
diff --git a/src/libutil/experimental-features.hh b/src/libutil/experimental-features.hh
index 3a254b423..266e41a22 100644
--- a/src/libutil/experimental-features.hh
+++ b/src/libutil/experimental-features.hh
@@ -49,10 +49,6 @@ public:
ExperimentalFeature missingFeature;
MissingExperimentalFeature(ExperimentalFeature);
- virtual const char * sname() const override
- {
- return "MissingExperimentalFeature";
- }
};
}
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc
index a4d632161..d2fd0c15a 100644
--- a/src/libutil/hash.cc
+++ b/src/libutil/hash.cc
@@ -155,7 +155,7 @@ static std::pair<std::optional<HashType>, bool> getParsedTypeAndSRI(std::string_
{
bool isSRI = false;
- // Parse the has type before the separater, if there was one.
+ // Parse the hash type before the separator, if there was one.
std::optional<HashType> optParsedType;
{
auto hashRaw = splitPrefixTo(rest, ':');
diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh
index 56b5938b3..00f70a572 100644
--- a/src/libutil/hash.hh
+++ b/src/libutil/hash.hh
@@ -93,13 +93,11 @@ public:
std::string gitRev() const
{
- assert(type == htSHA1);
return to_string(Base16, false);
}
std::string gitShortRev() const
{
- assert(type == htSHA1);
return std::string(to_string(Base16, false), 0, 7);
}
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 6445b3f1b..8ff904583 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -357,7 +357,7 @@ Sink & operator << (Sink & sink, const Error & ex)
sink
<< "Error"
<< info.level
- << info.name
+ << "Error" // removed
<< info.msg.str()
<< 0 // FIXME: info.errPos
<< info.traces.size();
@@ -426,11 +426,10 @@ Error readError(Source & source)
auto type = readString(source);
assert(type == "Error");
auto level = (Verbosity) readInt(source);
- auto name = readString(source);
+ auto name = readString(source); // removed
auto msg = readString(source);
ErrorInfo info {
.level = level,
- .name = name,
.msg = hintformat(std::move(format("%s") % msg)),
};
auto havePos = readNum<size_t>(source);
diff --git a/src/libutil/tests/url.cc b/src/libutil/tests/url.cc
index f20e2dc41..c3b233797 100644
--- a/src/libutil/tests/url.cc
+++ b/src/libutil/tests/url.cc
@@ -178,7 +178,7 @@ namespace nix {
}
TEST(parseURL, parseFileURLWithQueryAndFragment) {
- auto s = "file:///none/of/your/business";
+ auto s = "file:///none/of//your/business";
auto parsed = parseURL(s);
ParsedURL expected {
@@ -186,7 +186,7 @@ namespace nix {
.base = "",
.scheme = "file",
.authority = "",
- .path = "/none/of/your/business",
+ .path = "/none/of//your/business",
.query = (StringMap) { },
.fragment = "",
};
diff --git a/src/libutil/url-parts.hh b/src/libutil/url-parts.hh
index da10a6bbc..d5e6a2736 100644
--- a/src/libutil/url-parts.hh
+++ b/src/libutil/url-parts.hh
@@ -18,7 +18,7 @@ const static std::string userRegex = "(?:(?:" + unreservedRegex + "|" + pctEncod
const static std::string authorityRegex = "(?:" + userRegex + "@)?" + hostRegex + "(?::[0-9]+)?";
const static std::string pcharRegex = "(?:" + unreservedRegex + "|" + pctEncoded + "|" + subdelimsRegex + "|[:@])";
const static std::string queryRegex = "(?:" + pcharRegex + "|[/? \"])*";
-const static std::string segmentRegex = "(?:" + pcharRegex + "+)";
+const static std::string segmentRegex = "(?:" + pcharRegex + "*)";
const static std::string absPathRegex = "(?:(?:/" + segmentRegex + ")*/?)";
const static std::string pathRegex = "(?:" + segmentRegex + "(?:/" + segmentRegex + ")*/?)";
diff --git a/src/nix/eval.cc b/src/nix/eval.cc
index 8cd04d5fe..733b93661 100644
--- a/src/nix/eval.cc
+++ b/src/nix/eval.cc
@@ -16,7 +16,7 @@ struct CmdEval : MixJSON, InstallableCommand
std::optional<std::string> apply;
std::optional<Path> writeTo;
- CmdEval()
+ CmdEval() : InstallableCommand(true /* supportReadOnlyMode */)
{
addFlag({
.longName = "raw",