aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-06-26 08:46:46 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-06-26 08:46:46 +0200
commitadf2fbbdc2c94644b0d1023d844c7dc0e485a20f (patch)
tree5999d2c223cb24402995747d79a3de6d6aaebb73 /src/nix
parent09fc06daab280735dd2ec94276f00a9c5bffd9b2 (diff)
parentb7ccf7ae2af3d7eaf3696358ecbbce5a2bcfe652 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/add-to-store.cc5
-rw-r--r--src/nix/command.cc2
-rw-r--r--src/nix/develop.cc8
-rw-r--r--src/nix/hash.cc7
-rw-r--r--src/nix/make-content-addressable.cc5
-rw-r--r--src/nix/path-info.cc2
-rw-r--r--src/nix/profile.cc2
-rw-r--r--src/nix/repl.cc33
-rw-r--r--src/nix/show-derivation.cc6
-rw-r--r--src/nix/verify.cc6
10 files changed, 40 insertions, 36 deletions
diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc
index f43f774c1..f9d6de16e 100644
--- a/src/nix/add-to-store.cc
+++ b/src/nix/add-to-store.cc
@@ -48,7 +48,10 @@ struct CmdAddToStore : MixDryRun, StoreCommand
ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, *namePart));
info.narHash = narHash;
info.narSize = sink.s->size();
- info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash);
+ info.ca = std::optional { FixedOutputHash {
+ .method = FileIngestionMethod::Recursive,
+ .hash = info.narHash,
+ } };
if (!dryRun) {
auto source = StringSource { *sink.s };
diff --git a/src/nix/command.cc b/src/nix/command.cc
index f7ebf998d..dbf5e0988 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -4,7 +4,7 @@
#include "nixexpr.hh"
#include "profiles.hh"
-extern char * * environ;
+extern char * * environ __attribute__((weak));
namespace nix {
diff --git a/src/nix/develop.cc b/src/nix/develop.cc
index 06b165e41..9a50fd47e 100644
--- a/src/nix/develop.cc
+++ b/src/nix/develop.cc
@@ -135,7 +135,13 @@ StorePath getDerivationEnvironment(ref<Store> store, const StorePath & drvPath)
drv.inputSrcs.insert(std::move(getEnvShPath));
Hash h = hashDerivationModulo(*store, drv, true);
auto shellOutPath = store->makeOutputPath("out", h, drvName);
- drv.outputs.insert_or_assign("out", DerivationOutput { shellOutPath, "", "" });
+ drv.outputs.insert_or_assign("out", DerivationOutput {
+ .path = shellOutPath,
+ .hash = FixedOutputHash {
+ .method = FileIngestionMethod::Flat,
+ .hash = Hash { },
+ },
+ });
drv.env["out"] = store->printStorePath(shellOutPath);
auto shellDrvPath2 = writeDerivation(store, drv, drvName);
diff --git a/src/nix/hash.cc b/src/nix/hash.cc
index 7f646ad53..b94751e45 100644
--- a/src/nix/hash.cc
+++ b/src/nix/hash.cc
@@ -1,5 +1,6 @@
#include "command.hh"
#include "hash.hh"
+#include "content-address.hh"
#include "legacy.hh"
#include "shared.hh"
#include "references.hh"
@@ -83,12 +84,12 @@ static RegisterCommand r2("hash-path", [](){ return make_ref<CmdHash>(FileIngest
struct CmdToBase : Command
{
Base base;
- HashType ht = htUnknown;
+ std::optional<HashType> ht;
std::vector<std::string> args;
CmdToBase(Base base) : base(base)
{
- addFlag(Flag::mkHashTypeFlag("type", &ht));
+ addFlag(Flag::mkHashTypeOptFlag("type", &ht));
expectArgs("strings", &args);
}
@@ -136,8 +137,6 @@ static int compatNixHash(int argc, char * * argv)
else if (*arg == "--type") {
string s = getArg(*arg, arg, end);
ht = parseHashType(s);
- if (ht == htUnknown)
- throw UsageError("unknown hash type '%1%'", s);
}
else if (*arg == "--to-base16") op = opTo16;
else if (*arg == "--to-base32") op = opTo32;
diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc
index 0ebb8f13b..fb36fc410 100644
--- a/src/nix/make-content-addressable.cc
+++ b/src/nix/make-content-addressable.cc
@@ -82,7 +82,10 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
if (hasSelfReference) info.references.insert(info.path);
info.narHash = narHash;
info.narSize = sink.s->size();
- info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash);
+ info.ca = FixedOutputHash {
+ .method = FileIngestionMethod::Recursive,
+ .hash = info.narHash,
+ };
if (!json)
printInfo("rewrote '%s' to '%s'", pathS, store->printStorePath(info.path));
diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc
index fb7bacc4c..b89a44f83 100644
--- a/src/nix/path-info.cc
+++ b/src/nix/path-info.cc
@@ -115,7 +115,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
std::cout << '\t';
Strings ss;
if (info->ultimate) ss.push_back("ultimate");
- if (info->ca != "") ss.push_back("ca:" + info->ca);
+ if (info->ca) ss.push_back("ca:" + renderContentAddress(*info->ca));
for (auto & sig : info->sigs) ss.push_back(sig);
std::cout << concatStringsSep(" ", ss);
}
diff --git a/src/nix/profile.cc b/src/nix/profile.cc
index 3ba4f6e32..307e236d8 100644
--- a/src/nix/profile.cc
+++ b/src/nix/profile.cc
@@ -132,7 +132,7 @@ struct ProfileManifest
info.references = std::move(references);
info.narHash = narHash;
info.narSize = sink.s->size();
- info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash);
+ info.ca = FixedOutputHash { .method = FileIngestionMethod::Recursive, .hash = info.narHash };
auto source = StringSource { *sink.s };
store->addToStore(info, source);
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index 73b0ae521..c30ac2f79 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -19,6 +19,7 @@ extern "C" {
}
#endif
+#include "ansicolor.hh"
#include "shared.hh"
#include "eval.hh"
#include "eval-inline.hh"
@@ -37,14 +38,6 @@ extern "C" {
namespace nix {
-#define ESC_RED "\033[31m"
-#define ESC_GRE "\033[32m"
-#define ESC_YEL "\033[33m"
-#define ESC_BLU "\033[34;1m"
-#define ESC_MAG "\033[35m"
-#define ESC_CYA "\033[36m"
-#define ESC_END "\033[0m"
-
struct NixRepl : gc
{
string curDir;
@@ -645,25 +638,25 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
switch (v.type) {
case tInt:
- str << ESC_CYA << v.integer << ESC_END;
+ str << ANSI_CYAN << v.integer << ANSI_NORMAL;
break;
case tBool:
- str << ESC_CYA << (v.boolean ? "true" : "false") << ESC_END;
+ str << ANSI_CYAN << (v.boolean ? "true" : "false") << ANSI_NORMAL;
break;
case tString:
- str << ESC_YEL;
+ str << ANSI_YELLOW;
printStringValue(str, v.string.s);
- str << ESC_END;
+ str << ANSI_NORMAL;
break;
case tPath:
- str << ESC_GRE << v.path << ESC_END; // !!! escaping?
+ str << ANSI_GREEN << v.path << ANSI_NORMAL; // !!! escaping?
break;
case tNull:
- str << ESC_CYA "null" ESC_END;
+ str << ANSI_CYAN "null" ANSI_NORMAL;
break;
case tAttrs: {
@@ -699,7 +692,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
try {
printValue(str, *i.second, maxDepth - 1, seen);
} catch (AssertionError & e) {
- str << ESC_RED "«error: " << e.msg() << "»" ESC_END;
+ str << ANSI_RED "«error: " << e.msg() << "»" ANSI_NORMAL;
}
str << "; ";
}
@@ -725,7 +718,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
try {
printValue(str, *v.listElems()[n], maxDepth - 1, seen);
} catch (AssertionError & e) {
- str << ESC_RED "«error: " << e.msg() << "»" ESC_END;
+ str << ANSI_RED "«error: " << e.msg() << "»" ANSI_NORMAL;
}
str << " ";
}
@@ -737,16 +730,16 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
case tLambda: {
std::ostringstream s;
s << v.lambda.fun->pos;
- str << ESC_BLU "«lambda @ " << filterANSIEscapes(s.str()) << "»" ESC_END;
+ str << ANSI_BLUE "«lambda @ " << filterANSIEscapes(s.str()) << "»" ANSI_NORMAL;
break;
}
case tPrimOp:
- str << ESC_MAG "«primop»" ESC_END;
+ str << ANSI_MAGENTA "«primop»" ANSI_NORMAL;
break;
case tPrimOpApp:
- str << ESC_BLU "«primop-app»" ESC_END;
+ str << ANSI_BLUE "«primop-app»" ANSI_NORMAL;
break;
case tFloat:
@@ -754,7 +747,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
break;
default:
- str << ESC_RED "«unknown»" ESC_END;
+ str << ANSI_RED "«unknown»" ANSI_NORMAL;
break;
}
diff --git a/src/nix/show-derivation.cc b/src/nix/show-derivation.cc
index 2d31894c2..5d77cfdca 100644
--- a/src/nix/show-derivation.cc
+++ b/src/nix/show-derivation.cc
@@ -70,9 +70,9 @@ struct CmdShowDerivation : InstallablesCommand
for (auto & output : drv.outputs) {
auto outputObj(outputsObj.object(output.first));
outputObj.attr("path", store->printStorePath(output.second.path));
- if (output.second.hash != "") {
- outputObj.attr("hashAlgo", output.second.hashAlgo);
- outputObj.attr("hash", output.second.hash);
+ if (output.second.hash) {
+ outputObj.attr("hashAlgo", output.second.hash->printMethodAlgo());
+ outputObj.attr("hash", output.second.hash->hash.to_string(Base16, false));
}
}
}
diff --git a/src/nix/verify.cc b/src/nix/verify.cc
index ab83637dc..bb5e4529b 100644
--- a/src/nix/verify.cc
+++ b/src/nix/verify.cc
@@ -87,10 +87,10 @@ struct CmdVerify : StorePathsCommand
if (!noContents) {
std::unique_ptr<AbstractHashSink> hashSink;
- if (info->ca == "")
- hashSink = std::make_unique<HashSink>(info->narHash.type);
+ if (!info->ca)
+ hashSink = std::make_unique<HashSink>(*info->narHash.type);
else
- hashSink = std::make_unique<HashModuloSink>(info->narHash.type, std::string(info->path.hashPart()));
+ hashSink = std::make_unique<HashModuloSink>(*info->narHash.type, std::string(info->path.hashPart()));
store->narFromPath(info->path, *hashSink);