aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/attr-set.hh6
-rw-r--r--src/libexpr/primops.cc2
-rw-r--r--src/libstore/build.cc2
-rw-r--r--src/libstore/derivations.cc32
-rw-r--r--src/libstore/download.cc3
-rw-r--r--src/libstore/local-store.cc28
-rw-r--r--src/libstore/nar-info.cc2
-rw-r--r--src/libstore/path.cc5
-rw-r--r--src/libstore/path.hh6
-rw-r--r--src/libstore/ssh-store.cc6
-rw-r--r--src/libstore/ssh.cc10
-rw-r--r--src/libstore/store-api.hh2
-rw-r--r--src/libutil/logging.cc2
-rw-r--r--src/libutil/rust-ffi.hh2
-rw-r--r--src/libutil/util.hh1
-rwxr-xr-xsrc/nix-build/nix-build.cc6
-rw-r--r--src/nix/progress-bar.cc4
-rw-r--r--src/nix/why-depends.cc4
18 files changed, 72 insertions, 51 deletions
diff --git a/src/libexpr/attr-set.hh b/src/libexpr/attr-set.hh
index d6af99912..118c7bd5d 100644
--- a/src/libexpr/attr-set.hh
+++ b/src/libexpr/attr-set.hh
@@ -64,12 +64,12 @@ public:
return end();
}
- std::optional<Attr *> get(const Symbol & name)
+ Attr * get(const Symbol & name)
{
Attr key(name, 0);
iterator i = std::lower_bound(begin(), end(), key);
if (i != end() && i->name == name) return &*i;
- return {};
+ return nullptr;
}
Attr & need(const Symbol & name, const Pos & pos = noPos)
@@ -77,7 +77,7 @@ public:
auto a = get(name);
if (!a)
throw Error("attribute '%s' missing, at %s", name, pos);
- return **a;
+ return *a;
}
iterator begin() { return &attrs[0]; }
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 3ef827ebc..29302c9b6 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -731,6 +731,8 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
the hash. */
for (auto & i : outputs) {
if (!jsonObject) drv.env[i] = "";
+ drv.outputs.insert_or_assign(i,
+ DerivationOutput(StorePath::dummy.clone(), "", ""));
}
Hash h = hashDerivationModulo(*state.store, Derivation(drv), true);
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 74a68e1f5..9c6aedfa5 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -2579,6 +2579,7 @@ void DerivationGoal::writeStructuredAttrs()
}
writeFile(tmpDir + "/.attrs.json", rewriteStrings(json.dump(), inputRewrites));
+ chownToBuilder(tmpDir + "/.attrs.json");
/* As a convenience to bash scripts, write a shell file that
maps all attributes that are representable in bash -
@@ -2647,6 +2648,7 @@ void DerivationGoal::writeStructuredAttrs()
}
writeFile(tmpDir + "/.attrs.sh", rewriteStrings(jsonSh, inputRewrites));
+ chownToBuilder(tmpDir + "/.attrs.sh");
}
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index 1a061149a..d9da8769c 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -246,30 +246,18 @@ string Derivation::unparse(const Store & store, bool maskOutputs,
s.reserve(65536);
s += "Derive([";
- StringSet maskedOutputs;
-
- if (maskOutputs) {
- bool first = true;
- maskedOutputs = tokenizeString<StringSet>(get(env, "outputs").value_or("out"), " ");
- for (auto & i : maskedOutputs) {
- if (first) first = false; else s += ',';
- s += '('; printString(s, i);
- s += ",\"\",\"\",\"\")";
- }
- } else {
- bool first = true;
- for (auto & i : outputs) {
- if (first) first = false; else s += ',';
- s += '('; printString(s, i.first);
- s += ','; printString(s, store.printStorePath(i.second.path));
- s += ','; printString(s, i.second.hashAlgo);
- s += ','; printString(s, i.second.hash);
- s += ')';
- }
+ bool first = true;
+ for (auto & i : outputs) {
+ if (first) first = false; else s += ',';
+ s += '('; printString(s, i.first);
+ s += ','; printString(s, maskOutputs ? "" : store.printStorePath(i.second.path));
+ s += ','; printString(s, i.second.hashAlgo);
+ s += ','; printString(s, i.second.hash);
+ s += ')';
}
s += "],[";
- bool first = true;
+ first = true;
if (actualInputs) {
for (auto & i : *actualInputs) {
if (first) first = false; else s += ',';
@@ -299,7 +287,7 @@ string Derivation::unparse(const Store & store, bool maskOutputs,
for (auto & i : env) {
if (first) first = false; else s += ',';
s += '('; printString(s, i.first);
- s += ','; printString(s, maskOutputs && maskedOutputs.count(i.first) ? "" : i.second);
+ s += ','; printString(s, maskOutputs && outputs.count(i.first) ? "" : i.second);
s += ')';
}
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index 0c231ca1d..149c84765 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -363,9 +363,10 @@ struct CurlDownloader : public Downloader
} else if (httpStatus == 401 || httpStatus == 403 || httpStatus == 407) {
// Don't retry on authentication/authorization failures
err = Forbidden;
- } else if (httpStatus >= 400 && httpStatus < 500 && httpStatus != 408) {
+ } else if (httpStatus >= 400 && httpStatus < 500 && httpStatus != 408 && httpStatus != 429) {
// Most 4xx errors are client errors and are probably not worth retrying:
// * 408 means the server timed out waiting for us, so we try again
+ // * 429 means too many requests, so we retry (with a delay)
err = Misc;
} else if (httpStatus == 501 || httpStatus == 505 || httpStatus == 511) {
// Let's treat most 5xx (server) errors as transient, except for a handful:
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index b254d766a..e59624cd3 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -547,6 +547,18 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat
std::string drvName(drvPath.name());
drvName = string(drvName, 0, drvName.size() - drvExtension.size());
+ auto check = [&](const StorePath & expected, const StorePath & actual, const std::string & varName)
+ {
+ if (actual != expected)
+ throw Error("derivation '%s' has incorrect output '%s', should be '%s'",
+ printStorePath(drvPath), printStorePath(actual), printStorePath(expected));
+ auto j = drv.env.find(varName);
+ if (j == drv.env.end() || parseStorePath(j->second) != actual)
+ throw Error("derivation '%s' has incorrect environment variable '%s', should be '%s'",
+ printStorePath(drvPath), varName, printStorePath(actual));
+ };
+
+
if (drv.isFixedOutput()) {
DerivationOutputs::const_iterator out = drv.outputs.find("out");
if (out == drv.outputs.end())
@@ -554,24 +566,14 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat
bool recursive; Hash h;
out->second.parseHashInfo(recursive, h);
- auto outPath = makeFixedOutputPath(recursive, h, drvName);
- StringPairs::const_iterator j = drv.env.find("out");
- if (out->second.path != outPath || j == drv.env.end() || parseStorePath(j->second) != outPath)
- throw Error("derivation '%s' has incorrect output '%s', should be '%s'",
- printStorePath(drvPath), printStorePath(out->second.path), printStorePath(outPath));
+ check(makeFixedOutputPath(recursive, h, drvName), out->second.path, "out");
}
else {
Hash h = hashDerivationModulo(*this, drv, true);
-
- for (auto & i : drv.outputs) {
- auto outPath = makeOutputPath(i.first, h, drvName);
- StringPairs::const_iterator j = drv.env.find(i.first);
- if (i.second.path != outPath || j == drv.env.end() || parseStorePath(j->second) != outPath)
- throw Error("derivation '%s' has incorrect output '%s', should be '%s'",
- printStorePath(drvPath), printStorePath(i.second.path), printStorePath(outPath));
- }
+ for (auto & i : drv.outputs)
+ check(makeOutputPath(i.first, h, drvName), i.second.path, i.first);
}
}
diff --git a/src/libstore/nar-info.cc b/src/libstore/nar-info.cc
index fb02cf3fd..1375094b5 100644
--- a/src/libstore/nar-info.cc
+++ b/src/libstore/nar-info.cc
@@ -4,7 +4,7 @@
namespace nix {
NarInfo::NarInfo(const Store & store, const std::string & s, const std::string & whence)
- : ValidPathInfo(StorePath::make((unsigned char *) "xxxxxxxxxxxxxxxxxxxx", "x")) // FIXME: hack
+ : ValidPathInfo(StorePath::dummy.clone()) // FIXME: hack
{
auto corrupt = [&]() {
throw Error(format("NAR info file '%1%' is corrupt") % whence);
diff --git a/src/libstore/path.cc b/src/libstore/path.cc
index cda5f9968..a33bec3ed 100644
--- a/src/libstore/path.cc
+++ b/src/libstore/path.cc
@@ -46,12 +46,15 @@ std::string_view StorePath::name() const
return ffi_StorePath_name(*this);
}
+StorePath StorePath::dummy(
+ StorePath::make(
+ (unsigned char *) "xxxxxxxxxxxxxxxxxxxx", "x"));
+
StorePath Store::parseStorePath(std::string_view path) const
{
return StorePath::make(path, storeDir);
}
-
StorePathSet Store::parseStorePathSet(const PathSet & paths) const
{
StorePathSet res;
diff --git a/src/libstore/path.hh b/src/libstore/path.hh
index 5ebb57480..c90bb1fff 100644
--- a/src/libstore/path.hh
+++ b/src/libstore/path.hh
@@ -7,7 +7,7 @@ namespace nix {
/* See path.rs. */
struct StorePath;
-struct Store;
+class Store;
extern "C" {
void ffi_StorePath_drop(void *);
@@ -18,6 +18,8 @@ extern "C" {
struct StorePath : rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop>
{
+ StorePath() = delete;
+
static StorePath make(std::string_view path, std::string_view storeDir);
static StorePath make(unsigned char hash[20], std::string_view name);
@@ -53,6 +55,8 @@ struct StorePath : rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop>
{
return ffi_StorePath_hash_data(*this);
}
+
+ static StorePath dummy;
};
typedef std::set<StorePath> StorePathSet;
diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc
index 42ee06501..caae6b596 100644
--- a/src/libstore/ssh-store.cc
+++ b/src/libstore/ssh-store.cc
@@ -16,6 +16,8 @@ public:
const Setting<Path> sshKey{(Store*) this, "", "ssh-key", "path to an SSH private key"};
const Setting<bool> compress{(Store*) this, false, "compress", "whether to compress the connection"};
+ const Setting<Path> remoteProgram{(Store*) this, "nix-daemon", "remote-program", "path to the nix-daemon executable on the remote system"};
+ const Setting<std::string> remoteStore{(Store*) this, "", "remote-store", "URI of the store on the remote system"};
SSHStore(const std::string & host, const Params & params)
: Store(params)
@@ -82,7 +84,9 @@ ref<FSAccessor> SSHStore::getFSAccessor()
ref<RemoteStore::Connection> SSHStore::openConnection()
{
auto conn = make_ref<Connection>();
- conn->sshConn = master.startCommand("nix-daemon --stdio");
+ conn->sshConn = master.startCommand(
+ fmt("%s --stdio", remoteProgram)
+ + (remoteStore.get() == "" ? "" : " --store " + shellEscape(remoteStore.get())));
conn->to = FdSink(conn->sshConn->in.get());
conn->from = FdSource(conn->sshConn->out.get());
initConnection(*conn);
diff --git a/src/libstore/ssh.cc b/src/libstore/ssh.cc
index 2ee7115c5..84548a6e4 100644
--- a/src/libstore/ssh.cc
+++ b/src/libstore/ssh.cc
@@ -33,6 +33,9 @@ std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(const std::string
out.create();
auto conn = std::make_unique<Connection>();
+ ProcessOptions options;
+ options.dieWithParent = false;
+
conn->sshPid = startProcess([&]() {
restoreSignals();
@@ -64,7 +67,7 @@ std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(const std::string
// could not exec ssh/bash
throw SysError("unable to execute '%s'", args.front());
- });
+ }, options);
in.readSide = -1;
@@ -91,6 +94,9 @@ Path SSHMaster::startMaster()
Pipe out;
out.create();
+ ProcessOptions options;
+ options.dieWithParent = false;
+
state->sshMaster = startProcess([&]() {
restoreSignals();
@@ -110,7 +116,7 @@ Path SSHMaster::startMaster()
execvp(args.begin()->c_str(), stringsToCharPtrs(args).data());
throw SysError("unable to execute '%s'", args.front());
- });
+ }, options);
out.writeSide = -1;
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 743be9410..861b96930 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -676,7 +676,7 @@ class LocalFSStore : public virtual Store
public:
// FIXME: the (Store*) cast works around a bug in gcc that causes
- // it to emit the call to the Option constructor. Clang works fine
+ // it to omit the call to the Setting constructor. Clang works fine
// either way.
const PathSetting rootDir{(Store*) this, true, "",
"root", "directory prefixed to all other paths"};
diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc
index b379306f6..fa5c84a27 100644
--- a/src/libutil/logging.cc
+++ b/src/libutil/logging.cc
@@ -21,7 +21,7 @@ Logger * logger = makeDefaultLogger();
void Logger::warn(const std::string & msg)
{
- log(lvlWarn, ANSI_RED "warning:" ANSI_NORMAL " " + msg);
+ log(lvlWarn, ANSI_YELLOW "warning:" ANSI_NORMAL " " + msg);
}
class SimpleLogger : public Logger
diff --git a/src/libutil/rust-ffi.hh b/src/libutil/rust-ffi.hh
index 469a5fba3..228e2eead 100644
--- a/src/libutil/rust-ffi.hh
+++ b/src/libutil/rust-ffi.hh
@@ -113,6 +113,8 @@ extern "C" {
struct String : Vec<char, ffi_String_drop>
{
+ String() = delete;
+
String(std::string_view s)
{
ffi_String_new(StringSlice(s), this);
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index abf1c95d6..3bfebcd15 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -429,6 +429,7 @@ void ignoreException();
#define ANSI_FAINT "\e[2m"
#define ANSI_RED "\e[31;1m"
#define ANSI_GREEN "\e[32;1m"
+#define ANSI_YELLOW "\e[33;1m"
#define ANSI_BLUE "\e[34;1m"
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index d9bec431e..ff95ad787 100755
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -97,7 +97,11 @@ static void _main(int argc, char * * argv)
std::string outLink = "./result";
// 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"};
+ std::set<string> keepVars{
+ "HOME", "USER", "LOGNAME", "DISPLAY", "PATH", "TERM",
+ "IN_NIX_SHELL", "TZ", "PAGER", "NIX_BUILD_SHELL", "SHLVL",
+ "http_proxy", "https_proxy", "ftp_proxy", "all_proxy", "no_proxy"
+ };
Strings args;
for (int i = 1; i < argc; ++i)
diff --git a/src/nix/progress-bar.cc b/src/nix/progress-bar.cc
index c445f31cc..26631416c 100644
--- a/src/nix/progress-bar.cc
+++ b/src/nix/progress-bar.cc
@@ -446,7 +446,9 @@ public:
void startProgressBar(bool printBuildLogs)
{
- logger = new ProgressBar(printBuildLogs, isatty(STDERR_FILENO));
+ logger = new ProgressBar(
+ printBuildLogs,
+ isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb");
}
void stopProgressBar()
diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc
index 8566e5851..c24ae7c8e 100644
--- a/src/nix/why-depends.cc
+++ b/src/nix/why-depends.cc
@@ -103,7 +103,7 @@ struct CmdWhyDepends : SourceExprCommand
std::map<StorePath, Node> graph;
for (auto & path : closure)
- graph.emplace(path.clone(), Node{path.clone(), cloneStorePathSet(store->queryPathInfo(path)->references)});
+ graph.emplace(path.clone(), Node { .path = path.clone(), .refs = cloneStorePathSet(store->queryPathInfo(path)->references) });
// Transpose the graph.
for (auto & node : graph)
@@ -112,7 +112,7 @@ struct CmdWhyDepends : SourceExprCommand
/* Run Dijkstra's shortest path algorithm to get the distance
of every path in the closure to 'dependency'. */
- graph[dependencyPath.clone()].dist = 0;
+ graph.emplace(dependencyPath.clone(), Node { .path = dependencyPath.clone(), .dist = 0 });
std::priority_queue<Node *> queue;