aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/command.cc2
-rw-r--r--src/nix/hash.cc6
-rw-r--r--src/nix/repl.cc33
-rw-r--r--src/nix/verify.cc4
4 files changed, 18 insertions, 27 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc
index d62626c26..3651a9e9c 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/hash.cc b/src/nix/hash.cc
index 0dd4998d9..f435192fc 100644
--- a/src/nix/hash.cc
+++ b/src/nix/hash.cc
@@ -79,12 +79,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);
}
@@ -132,8 +132,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/repl.cc b/src/nix/repl.cc
index 4bcaaeebf..617d49614 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/verify.cc b/src/nix/verify.cc
index ab83637dc..d1aba08e3 100644
--- a/src/nix/verify.cc
+++ b/src/nix/verify.cc
@@ -88,9 +88,9 @@ struct CmdVerify : StorePathsCommand
std::unique_ptr<AbstractHashSink> hashSink;
if (info->ca == "")
- hashSink = std::make_unique<HashSink>(info->narHash.type);
+ 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);