forked from lix-project/lix
Merge remote-tracking branch 'origin/master' into markdown
This commit is contained in:
commit
84f5cabbea
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -13,5 +13,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: cachix/install-nix-action@v10
|
- uses: cachix/install-nix-action@v10
|
||||||
|
with:
|
||||||
|
skip_adding_nixpkgs_channel: true
|
||||||
#- run: nix flake check
|
#- run: nix flake check
|
||||||
- run: nix-build -A checks.$(if [[ `uname` = Linux ]]; then echo x86_64-linux; else echo x86_64-darwin; fi)
|
- run: nix-build -A checks.$(if [[ `uname` = Linux ]]; then echo x86_64-linux; else echo x86_64-darwin; fi)
|
||||||
|
|
|
@ -52,8 +52,13 @@ Most Nix commands accept the following command-line options:
|
||||||
This is the raw format, as outputted by nix-build.
|
This is the raw format, as outputted by nix-build.
|
||||||
|
|
||||||
- internal-json
|
- internal-json
|
||||||
Outputs the logs in a structured manner. NOTE: the json schema
|
Outputs the logs in a structured manner.
|
||||||
is not guarantees to be stable between releases.
|
|
||||||
|
> **Warning**
|
||||||
|
>
|
||||||
|
> While the schema itself is relatively stable, the format of
|
||||||
|
> the error-messages (namely of the `msg`-field) can change
|
||||||
|
> between releases.
|
||||||
|
|
||||||
- bar
|
- bar
|
||||||
Only display a progress bar during the builds.
|
Only display a progress bar during the builds.
|
||||||
|
|
|
@ -14,7 +14,7 @@ To build Nix for the current operating system/architecture use
|
||||||
$ nix-build
|
$ nix-build
|
||||||
```
|
```
|
||||||
|
|
||||||
or if you have a flakes-enabled nix:
|
or if you have a flake-enabled nix:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ nix build
|
$ nix build
|
||||||
|
@ -52,6 +52,12 @@ To install it in `$(pwd)/inst` and test it:
|
||||||
nix (Nix) 2.4
|
nix (Nix) 2.4
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To run a functional test:
|
||||||
|
|
||||||
|
```console
|
||||||
|
make tests/test-name-should-auto-complete.sh.test
|
||||||
|
```
|
||||||
|
|
||||||
If you have a flakes-enabled Nix you can replace:
|
If you have a flakes-enabled Nix you can replace:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
|
|
|
@ -442,6 +442,8 @@
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = "nix";
|
name = "nix";
|
||||||
|
|
||||||
|
outputs = [ "out" "dev" "doc" ];
|
||||||
|
|
||||||
buildInputs = buildDeps ++ propagatedDeps ++ perlDeps;
|
buildInputs = buildDeps ++ propagatedDeps ++ perlDeps;
|
||||||
|
|
||||||
inherit configureFlags;
|
inherit configureFlags;
|
||||||
|
@ -452,12 +454,7 @@
|
||||||
|
|
||||||
shellHook =
|
shellHook =
|
||||||
''
|
''
|
||||||
export prefix=$(pwd)/inst
|
export MANPATH=$out/share/man:$MANPATH
|
||||||
configureFlags+=" --prefix=$prefix"
|
|
||||||
PKG_CONFIG_PATH=$prefix/lib/pkgconfig:$PKG_CONFIG_PATH
|
|
||||||
PATH=$prefix/bin:$PATH
|
|
||||||
export MANPATH=/home/eelco/Dev/nix/inst/share/man:$MANPATH
|
|
||||||
unset PYTHONPATH
|
|
||||||
'';
|
'';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ define run-install-test
|
||||||
|
|
||||||
.PHONY: $1.test
|
.PHONY: $1.test
|
||||||
$1.test: $1 $(test-deps)
|
$1.test: $1 $(test-deps)
|
||||||
@env TEST_NAME=$(notdir $(basename $1)) TESTS_ENVIRONMENT="$(tests-environment)" mk/run_test.sh $1
|
@env TEST_NAME=$(notdir $(basename $1)) TESTS_ENVIRONMENT="$(tests-environment)" mk/run_test.sh $1 < /dev/null
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
makefiles = local.mk
|
makefiles = local.mk
|
||||||
|
|
||||||
GLOBAL_CXXFLAGS += -g -Wall
|
GLOBAL_CXXFLAGS += -g -Wall -std=c++17
|
||||||
|
|
||||||
-include Makefile.config
|
-include Makefile.config
|
||||||
|
|
||||||
|
|
|
@ -1350,13 +1350,24 @@ void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res)
|
||||||
Value * actualArgs = allocValue();
|
Value * actualArgs = allocValue();
|
||||||
mkAttrs(*actualArgs, fun.lambda.fun->formals->formals.size());
|
mkAttrs(*actualArgs, fun.lambda.fun->formals->formals.size());
|
||||||
|
|
||||||
|
if (fun.lambda.fun->formals->ellipsis) {
|
||||||
|
// If the formals have an ellipsis (eg the function accepts extra args) pass
|
||||||
|
// all available automatic arguments (which includes arguments specified on
|
||||||
|
// the command line via --arg/--argstr)
|
||||||
|
for (auto& v : args) {
|
||||||
|
actualArgs->attrs->push_back(v);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Otherwise, only pass the arguments that the function accepts
|
||||||
for (auto & i : fun.lambda.fun->formals->formals) {
|
for (auto & i : fun.lambda.fun->formals->formals) {
|
||||||
Bindings::iterator j = args.find(i.name);
|
Bindings::iterator j = args.find(i.name);
|
||||||
if (j != args.end())
|
if (j != args.end()) {
|
||||||
actualArgs->attrs->push_back(*j);
|
actualArgs->attrs->push_back(*j);
|
||||||
else if (!i.def)
|
} else if (!i.def) {
|
||||||
throwTypeError("cannot auto-call a function that has an argument without a default value ('%1%')", i.name);
|
throwTypeError("cannot auto-call a function that has an argument without a default value ('%1%')", i.name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
actualArgs->attrs->sort();
|
actualArgs->attrs->sort();
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS
|
||||||
|
|
||||||
if (auto optStorePath = isValidDerivationInStore()) {
|
if (auto optStorePath = isValidDerivationInStore()) {
|
||||||
auto storePath = *optStorePath;
|
auto storePath = *optStorePath;
|
||||||
Derivation drv = readDerivation(*state.store, realPath, Derivation::nameFromPath(storePath));
|
Derivation drv = state.store->readDerivation(storePath);
|
||||||
Value & w = *state.allocValue();
|
Value & w = *state.allocValue();
|
||||||
state.mkAttrs(w, 3 + drv.outputs.size());
|
state.mkAttrs(w, 3 + drv.outputs.size());
|
||||||
Value * v2 = state.allocAttr(w, state.sDrvPath);
|
Value * v2 = state.allocAttr(w, state.sDrvPath);
|
||||||
|
|
|
@ -185,7 +185,7 @@ static DerivationOutput parseDerivationOutput(const Store & store, std::istrings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Derivation parseDerivation(const Store & store, std::string && s, std::string_view name)
|
Derivation parseDerivation(const Store & store, std::string && s, std::string_view name)
|
||||||
{
|
{
|
||||||
Derivation drv;
|
Derivation drv;
|
||||||
drv.name = name;
|
drv.name = name;
|
||||||
|
@ -233,34 +233,6 @@ static Derivation parseDerivation(const Store & store, std::string && s, std::st
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Derivation readDerivation(const Store & store, const Path & drvPath, std::string_view name)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return parseDerivation(store, readFile(drvPath), name);
|
|
||||||
} catch (FormatError & e) {
|
|
||||||
throw Error("error parsing derivation '%1%': %2%", drvPath, e.msg());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Derivation Store::derivationFromPath(const StorePath & drvPath)
|
|
||||||
{
|
|
||||||
ensurePath(drvPath);
|
|
||||||
return readDerivation(drvPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Derivation Store::readDerivation(const StorePath & drvPath)
|
|
||||||
{
|
|
||||||
auto accessor = getFSAccessor();
|
|
||||||
try {
|
|
||||||
return parseDerivation(*this, accessor->readFile(printStorePath(drvPath)), Derivation::nameFromPath(drvPath));
|
|
||||||
} catch (FormatError & e) {
|
|
||||||
throw Error("error parsing derivation '%s': %s", printStorePath(drvPath), e.msg());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void printString(string & res, std::string_view s)
|
static void printString(string & res, std::string_view s)
|
||||||
{
|
{
|
||||||
char buf[s.size() * 2 + 2];
|
char buf[s.size() * 2 + 2];
|
||||||
|
|
|
@ -150,7 +150,7 @@ StorePath writeDerivation(Store & store,
|
||||||
const Derivation & drv, RepairFlag repair = NoRepair);
|
const Derivation & drv, RepairFlag repair = NoRepair);
|
||||||
|
|
||||||
/* Read a derivation from a file. */
|
/* Read a derivation from a file. */
|
||||||
Derivation readDerivation(const Store & store, const Path & drvPath, std::string_view name);
|
Derivation parseDerivation(const Store & store, std::string && s, std::string_view name);
|
||||||
|
|
||||||
// FIXME: remove
|
// FIXME: remove
|
||||||
bool isDerivation(const string & fileName);
|
bool isDerivation(const string & fileName);
|
||||||
|
|
|
@ -23,9 +23,6 @@ namespace nix {
|
||||||
const int nixSchemaVersion = 10;
|
const int nixSchemaVersion = 10;
|
||||||
|
|
||||||
|
|
||||||
struct Derivation;
|
|
||||||
|
|
||||||
|
|
||||||
struct OptimiseStats
|
struct OptimiseStats
|
||||||
{
|
{
|
||||||
unsigned long filesLinked = 0;
|
unsigned long filesLinked = 0;
|
||||||
|
|
|
@ -284,9 +284,9 @@ struct ConnectionHandle
|
||||||
|
|
||||||
RemoteStore::Connection * operator -> () { return &*handle; }
|
RemoteStore::Connection * operator -> () { return &*handle; }
|
||||||
|
|
||||||
void processStderr(Sink * sink = 0, Source * source = 0)
|
void processStderr(Sink * sink = 0, Source * source = 0, bool flush = true)
|
||||||
{
|
{
|
||||||
auto ex = handle->processStderr(sink, source);
|
auto ex = handle->processStderr(sink, source, flush);
|
||||||
if (ex) {
|
if (ex) {
|
||||||
daemonException = true;
|
daemonException = true;
|
||||||
std::rethrow_exception(ex);
|
std::rethrow_exception(ex);
|
||||||
|
@ -535,6 +535,8 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
|
||||||
|
|
||||||
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 23) {
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 23) {
|
||||||
|
|
||||||
|
conn->to.flush();
|
||||||
|
|
||||||
std::exception_ptr ex;
|
std::exception_ptr ex;
|
||||||
|
|
||||||
struct FramedSink : BufferedSink
|
struct FramedSink : BufferedSink
|
||||||
|
@ -574,7 +576,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
|
||||||
std::thread stderrThread([&]()
|
std::thread stderrThread([&]()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
conn.processStderr();
|
conn.processStderr(nullptr, nullptr, false);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ex = std::current_exception();
|
ex = std::current_exception();
|
||||||
}
|
}
|
||||||
|
@ -884,8 +886,9 @@ static Logger::Fields readFields(Source & from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::exception_ptr RemoteStore::Connection::processStderr(Sink * sink, Source * source)
|
std::exception_ptr RemoteStore::Connection::processStderr(Sink * sink, Source * source, bool flush)
|
||||||
{
|
{
|
||||||
|
if (flush)
|
||||||
to.flush();
|
to.flush();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
@ -114,7 +114,7 @@ protected:
|
||||||
|
|
||||||
virtual ~Connection();
|
virtual ~Connection();
|
||||||
|
|
||||||
std::exception_ptr processStderr(Sink * sink = 0, Source * source = 0);
|
std::exception_ptr processStderr(Sink * sink = 0, Source * source = 0, bool flush = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
ref<Connection> openConnectionWrapper();
|
ref<Connection> openConnectionWrapper();
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include "crypto.hh"
|
#include "crypto.hh"
|
||||||
|
#include "fs-accessor.hh"
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "nar-info-disk-cache.hh"
|
#include "nar-info-disk-cache.hh"
|
||||||
#include "thread-pool.hh"
|
#include "thread-pool.hh"
|
||||||
#include "json.hh"
|
#include "json.hh"
|
||||||
#include "derivations.hh"
|
|
||||||
#include "url.hh"
|
#include "url.hh"
|
||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
|
|
||||||
|
@ -983,6 +983,26 @@ Strings ValidPathInfo::shortRefs() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Derivation Store::derivationFromPath(const StorePath & drvPath)
|
||||||
|
{
|
||||||
|
ensurePath(drvPath);
|
||||||
|
return readDerivation(drvPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Derivation Store::readDerivation(const StorePath & drvPath)
|
||||||
|
{
|
||||||
|
auto accessor = getFSAccessor();
|
||||||
|
try {
|
||||||
|
return parseDerivation(*this,
|
||||||
|
accessor->readFile(printStorePath(drvPath)),
|
||||||
|
Derivation::nameFromPath(drvPath));
|
||||||
|
} catch (FormatError & e) {
|
||||||
|
throw Error("error parsing derivation '%s': %s", printStorePath(drvPath), e.msg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -184,6 +184,33 @@ struct JSONLogger : Logger {
|
||||||
json["action"] = "msg";
|
json["action"] = "msg";
|
||||||
json["level"] = ei.level;
|
json["level"] = ei.level;
|
||||||
json["msg"] = oss.str();
|
json["msg"] = oss.str();
|
||||||
|
json["raw_msg"] = ei.hint->str();
|
||||||
|
|
||||||
|
if (ei.errPos.has_value() && (*ei.errPos)) {
|
||||||
|
json["line"] = ei.errPos->line;
|
||||||
|
json["column"] = ei.errPos->column;
|
||||||
|
json["file"] = ei.errPos->file;
|
||||||
|
} else {
|
||||||
|
json["line"] = nullptr;
|
||||||
|
json["column"] = nullptr;
|
||||||
|
json["file"] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loggerSettings.showTrace.get() && !ei.traces.empty()) {
|
||||||
|
nlohmann::json traces = nlohmann::json::array();
|
||||||
|
for (auto iter = ei.traces.rbegin(); iter != ei.traces.rend(); ++iter) {
|
||||||
|
nlohmann::json stackFrame;
|
||||||
|
stackFrame["raw_msg"] = iter->hint.str();
|
||||||
|
if (iter->pos.has_value() && (*iter->pos)) {
|
||||||
|
stackFrame["line"] = iter->pos->line;
|
||||||
|
stackFrame["column"] = iter->pos->column;
|
||||||
|
stackFrame["file"] = iter->pos->file;
|
||||||
|
}
|
||||||
|
traces.push_back(stackFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
json["trace"] = traces;
|
||||||
|
}
|
||||||
|
|
||||||
write(json);
|
write(json);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,8 @@ struct Sink
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* A buffered abstract sink. */
|
/* A buffered abstract sink. Warning: a BufferedSink should not be
|
||||||
|
used from multiple threads concurrently. */
|
||||||
struct BufferedSink : virtual Sink
|
struct BufferedSink : virtual Sink
|
||||||
{
|
{
|
||||||
size_t bufSize, bufPos;
|
size_t bufSize, bufPos;
|
||||||
|
@ -66,7 +67,8 @@ struct Source
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* A buffered abstract source. */
|
/* A buffered abstract source. Warning: a BufferedSource should not be
|
||||||
|
used from multiple threads concurrently. */
|
||||||
struct BufferedSource : Source
|
struct BufferedSource : Source
|
||||||
{
|
{
|
||||||
size_t bufSize, bufPosIn, bufPosOut;
|
size_t bufSize, bufPosIn, bufPosOut;
|
||||||
|
|
|
@ -34,6 +34,24 @@ namespace nix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(logEI, jsonOutput) {
|
||||||
|
SymbolTable testTable;
|
||||||
|
auto problem_file = testTable.create("random.nix");
|
||||||
|
testing::internal::CaptureStderr();
|
||||||
|
|
||||||
|
makeJSONLogger(*logger)->logEI({
|
||||||
|
.name = "error name",
|
||||||
|
.description = "error without any code lines.",
|
||||||
|
.hint = hintfmt("this hint has %1% templated %2%!!",
|
||||||
|
"yellow",
|
||||||
|
"values"),
|
||||||
|
.errPos = Pos(foFile, problem_file, 02, 13)
|
||||||
|
});
|
||||||
|
|
||||||
|
auto str = testing::internal::GetCapturedStderr();
|
||||||
|
ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- SysError --- error-unit-test\x1B[0m\nopening file '\x1B[33;1mrandom.nix\x1B[0m': \x1B[33;1mNo such file or directory\x1B[0m\n@nix {\"action\":\"msg\",\"column\":13,\"file\":\"random.nix\",\"level\":0,\"line\":2,\"msg\":\"\\u001b[31;1merror:\\u001b[0m\\u001b[34;1m --- error name --- error-unit-test\\u001b[0m\\n\\u001b[34;1mat: \\u001b[33;1m(2:13)\\u001b[34;1m in file: \\u001b[0mrandom.nix\\n\\nerror without any code lines.\\n\\nthis hint has \\u001b[33;1myellow\\u001b[0m templated \\u001b[33;1mvalues\\u001b[0m!!\",\"raw_msg\":\"this hint has \\u001b[33;1myellow\\u001b[0m templated \\u001b[33;1mvalues\\u001b[0m!!\"}\n");
|
||||||
|
}
|
||||||
|
|
||||||
TEST(logEI, appendingHintsToPreviousError) {
|
TEST(logEI, appendingHintsToPreviousError) {
|
||||||
|
|
||||||
MakeError(TestError, Error);
|
MakeError(TestError, Error);
|
||||||
|
|
|
@ -15,7 +15,7 @@ struct Var
|
||||||
{
|
{
|
||||||
bool exported = true;
|
bool exported = true;
|
||||||
bool associative = false;
|
bool associative = false;
|
||||||
std::string value; // quoted string or array
|
std::string quoted; // quoted string or array
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BuildEnvironment
|
struct BuildEnvironment
|
||||||
|
@ -75,12 +75,12 @@ BuildEnvironment readEnvironment(const Path & path)
|
||||||
|
|
||||||
else if (std::regex_search(pos, file.cend(), match, varRegex, std::regex_constants::match_continuous)) {
|
else if (std::regex_search(pos, file.cend(), match, varRegex, std::regex_constants::match_continuous)) {
|
||||||
pos = match[0].second;
|
pos = match[0].second;
|
||||||
res.env.insert({match[1], Var { .exported = exported.count(match[1]) > 0, .value = match[2] }});
|
res.env.insert({match[1], Var { .exported = exported.count(match[1]) > 0, .quoted = match[2] }});
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::regex_search(pos, file.cend(), match, assocArrayRegex, std::regex_constants::match_continuous)) {
|
else if (std::regex_search(pos, file.cend(), match, assocArrayRegex, std::regex_constants::match_continuous)) {
|
||||||
pos = match[0].second;
|
pos = match[0].second;
|
||||||
res.env.insert({match[1], Var { .associative = true, .value = match[2] }});
|
res.env.insert({match[1], Var { .associative = true, .quoted = match[2] }});
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::regex_search(pos, file.cend(), match, functionRegex, std::regex_constants::match_continuous)) {
|
else if (std::regex_search(pos, file.cend(), match, functionRegex, std::regex_constants::match_continuous)) {
|
||||||
|
@ -92,6 +92,8 @@ BuildEnvironment readEnvironment(const Path & path)
|
||||||
path, file.substr(pos - file.cbegin(), 60));
|
path, file.substr(pos - file.cbegin(), 60));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.env.erase("__output");
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,27 +127,32 @@ StorePath getDerivationEnvironment(ref<Store> store, const StorePath & drvPath)
|
||||||
/* Rehash and write the derivation. FIXME: would be nice to use
|
/* Rehash and write the derivation. FIXME: would be nice to use
|
||||||
'buildDerivation', but that's privileged. */
|
'buildDerivation', but that's privileged. */
|
||||||
drv.name += "-env";
|
drv.name += "-env";
|
||||||
for (auto & output : drv.outputs)
|
for (auto & output : drv.outputs) {
|
||||||
drv.env.erase(output.first);
|
output.second = { .output = DerivationOutputInputAddressed { .path = StorePath::dummy } };
|
||||||
drv.outputs = {{"out", DerivationOutput { .output = DerivationOutputInputAddressed { .path = StorePath::dummy }}}};
|
drv.env[output.first] = "";
|
||||||
drv.env["out"] = "";
|
}
|
||||||
drv.env["_outputs_saved"] = drv.env["outputs"];
|
|
||||||
drv.env["outputs"] = "out";
|
|
||||||
drv.inputSrcs.insert(std::move(getEnvShPath));
|
drv.inputSrcs.insert(std::move(getEnvShPath));
|
||||||
Hash h = std::get<0>(hashDerivationModulo(*store, drv, true));
|
Hash h = std::get<0>(hashDerivationModulo(*store, drv, true));
|
||||||
auto shellOutPath = store->makeOutputPath("out", h, drv.name);
|
|
||||||
drv.outputs.insert_or_assign("out", DerivationOutput { .output = DerivationOutputInputAddressed {
|
for (auto & output : drv.outputs) {
|
||||||
.path = shellOutPath
|
auto outPath = store->makeOutputPath(output.first, h, drv.name);
|
||||||
} });
|
output.second = { .output = DerivationOutputInputAddressed { .path = outPath } };
|
||||||
drv.env["out"] = store->printStorePath(shellOutPath);
|
drv.env[output.first] = store->printStorePath(outPath);
|
||||||
auto shellDrvPath2 = writeDerivation(*store, drv);
|
}
|
||||||
|
|
||||||
|
auto shellDrvPath = writeDerivation(*store, drv);
|
||||||
|
|
||||||
/* Build the derivation. */
|
/* Build the derivation. */
|
||||||
store->buildPaths({{shellDrvPath2}});
|
store->buildPaths({{shellDrvPath}});
|
||||||
|
|
||||||
assert(store->isValidPath(shellOutPath));
|
for (auto & outPath : drv.outputPaths(*store)) {
|
||||||
|
assert(store->isValidPath(outPath));
|
||||||
|
auto outPathS = store->toRealPath(outPath);
|
||||||
|
if (lstat(outPathS).st_size)
|
||||||
|
return outPath;
|
||||||
|
}
|
||||||
|
|
||||||
return shellOutPath;
|
throw Error("get-env.sh failed to produce an environment");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Common : InstallableCommand, MixProfile
|
struct Common : InstallableCommand, MixProfile
|
||||||
|
@ -171,8 +178,12 @@ struct Common : InstallableCommand, MixProfile
|
||||||
"UID",
|
"UID",
|
||||||
};
|
};
|
||||||
|
|
||||||
void makeRcScript(const BuildEnvironment & buildEnvironment, std::ostream & out)
|
std::string makeRcScript(
|
||||||
|
const BuildEnvironment & buildEnvironment,
|
||||||
|
const Path & outputsDir = absPath(".") + "/outputs")
|
||||||
{
|
{
|
||||||
|
std::ostringstream out;
|
||||||
|
|
||||||
out << "unset shellHook\n";
|
out << "unset shellHook\n";
|
||||||
|
|
||||||
out << "nix_saved_PATH=\"$PATH\"\n";
|
out << "nix_saved_PATH=\"$PATH\"\n";
|
||||||
|
@ -180,9 +191,9 @@ struct Common : InstallableCommand, MixProfile
|
||||||
for (auto & i : buildEnvironment.env) {
|
for (auto & i : buildEnvironment.env) {
|
||||||
if (!ignoreVars.count(i.first) && !hasPrefix(i.first, "BASH_")) {
|
if (!ignoreVars.count(i.first) && !hasPrefix(i.first, "BASH_")) {
|
||||||
if (i.second.associative)
|
if (i.second.associative)
|
||||||
out << fmt("declare -A %s=(%s)\n", i.first, i.second.value);
|
out << fmt("declare -A %s=(%s)\n", i.first, i.second.quoted);
|
||||||
else {
|
else {
|
||||||
out << fmt("%s=%s\n", i.first, i.second.value);
|
out << fmt("%s=%s\n", i.first, i.second.quoted);
|
||||||
if (i.second.exported)
|
if (i.second.exported)
|
||||||
out << fmt("export %s\n", i.first);
|
out << fmt("export %s\n", i.first);
|
||||||
}
|
}
|
||||||
|
@ -193,13 +204,26 @@ struct Common : InstallableCommand, MixProfile
|
||||||
|
|
||||||
out << buildEnvironment.bashFunctions << "\n";
|
out << buildEnvironment.bashFunctions << "\n";
|
||||||
|
|
||||||
// FIXME: set outputs
|
|
||||||
|
|
||||||
out << "export NIX_BUILD_TOP=\"$(mktemp -d --tmpdir nix-shell.XXXXXX)\"\n";
|
out << "export NIX_BUILD_TOP=\"$(mktemp -d --tmpdir nix-shell.XXXXXX)\"\n";
|
||||||
for (auto & i : {"TMP", "TMPDIR", "TEMP", "TEMPDIR"})
|
for (auto & i : {"TMP", "TMPDIR", "TEMP", "TEMPDIR"})
|
||||||
out << fmt("export %s=\"$NIX_BUILD_TOP\"\n", i);
|
out << fmt("export %s=\"$NIX_BUILD_TOP\"\n", i);
|
||||||
|
|
||||||
out << "eval \"$shellHook\"\n";
|
out << "eval \"$shellHook\"\n";
|
||||||
|
|
||||||
|
/* Substitute occurrences of output paths. */
|
||||||
|
auto outputs = buildEnvironment.env.find("outputs");
|
||||||
|
assert(outputs != buildEnvironment.env.end());
|
||||||
|
|
||||||
|
// FIXME: properly unquote 'outputs'.
|
||||||
|
StringMap rewrites;
|
||||||
|
for (auto & outputName : tokenizeString<std::vector<std::string>>(replaceStrings(outputs->second.quoted, "'", ""))) {
|
||||||
|
auto from = buildEnvironment.env.find(outputName);
|
||||||
|
assert(from != buildEnvironment.env.end());
|
||||||
|
// FIXME: unquote
|
||||||
|
rewrites.insert({from->second.quoted, outputsDir + "/" + outputName});
|
||||||
|
}
|
||||||
|
|
||||||
|
return rewriteStrings(out.str(), rewrites);
|
||||||
}
|
}
|
||||||
|
|
||||||
Strings getDefaultFlakeAttrPaths() override
|
Strings getDefaultFlakeAttrPaths() override
|
||||||
|
@ -240,6 +264,7 @@ struct Common : InstallableCommand, MixProfile
|
||||||
struct CmdDevelop : Common, MixEnvironment
|
struct CmdDevelop : Common, MixEnvironment
|
||||||
{
|
{
|
||||||
std::vector<std::string> command;
|
std::vector<std::string> command;
|
||||||
|
std::optional<std::string> phase;
|
||||||
|
|
||||||
CmdDevelop()
|
CmdDevelop()
|
||||||
{
|
{
|
||||||
|
@ -253,6 +278,43 @@ struct CmdDevelop : Common, MixEnvironment
|
||||||
command = ss;
|
command = ss;
|
||||||
}}
|
}}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addFlag({
|
||||||
|
.longName = "phase",
|
||||||
|
.description = "phase to run (e.g. `build` or `configure`)",
|
||||||
|
.labels = {"phase-name"},
|
||||||
|
.handler = {&phase},
|
||||||
|
});
|
||||||
|
|
||||||
|
addFlag({
|
||||||
|
.longName = "configure",
|
||||||
|
.description = "run the configure phase",
|
||||||
|
.handler = {&phase, {"configure"}},
|
||||||
|
});
|
||||||
|
|
||||||
|
addFlag({
|
||||||
|
.longName = "build",
|
||||||
|
.description = "run the build phase",
|
||||||
|
.handler = {&phase, {"build"}},
|
||||||
|
});
|
||||||
|
|
||||||
|
addFlag({
|
||||||
|
.longName = "check",
|
||||||
|
.description = "run the check phase",
|
||||||
|
.handler = {&phase, {"check"}},
|
||||||
|
});
|
||||||
|
|
||||||
|
addFlag({
|
||||||
|
.longName = "install",
|
||||||
|
.description = "run the install phase",
|
||||||
|
.handler = {&phase, {"install"}},
|
||||||
|
});
|
||||||
|
|
||||||
|
addFlag({
|
||||||
|
.longName = "installcheck",
|
||||||
|
.description = "run the installcheck phase",
|
||||||
|
.handler = {&phase, {"installCheck"}},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string description() override
|
std::string description() override
|
||||||
|
@ -288,19 +350,31 @@ struct CmdDevelop : Common, MixEnvironment
|
||||||
|
|
||||||
auto [rcFileFd, rcFilePath] = createTempFile("nix-shell");
|
auto [rcFileFd, rcFilePath] = createTempFile("nix-shell");
|
||||||
|
|
||||||
std::ostringstream ss;
|
auto script = makeRcScript(buildEnvironment);
|
||||||
makeRcScript(buildEnvironment, ss);
|
|
||||||
|
|
||||||
ss << fmt("rm -f '%s'\n", rcFilePath);
|
if (verbosity >= lvlDebug)
|
||||||
|
script += "set -x\n";
|
||||||
|
|
||||||
if (!command.empty()) {
|
script += fmt("rm -f '%s'\n", rcFilePath);
|
||||||
|
|
||||||
|
if (phase) {
|
||||||
|
if (!command.empty())
|
||||||
|
throw UsageError("you cannot use both '--command' and '--phase'");
|
||||||
|
// FIXME: foundMakefile is set by buildPhase, need to get
|
||||||
|
// rid of that.
|
||||||
|
script += fmt("foundMakefile=1\n");
|
||||||
|
script += fmt("runHook %1%Phase\n", *phase);
|
||||||
|
script += fmt("exit 0\n", *phase);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!command.empty()) {
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
for (auto s : command)
|
for (auto s : command)
|
||||||
args.push_back(shellEscape(s));
|
args.push_back(shellEscape(s));
|
||||||
ss << fmt("exec %s\n", concatStringsSep(" ", args));
|
script += fmt("exec %s\n", concatStringsSep(" ", args));
|
||||||
}
|
}
|
||||||
|
|
||||||
writeFull(rcFileFd.get(), ss.str());
|
writeFull(rcFileFd.get(), script);
|
||||||
|
|
||||||
stopProgressBar();
|
stopProgressBar();
|
||||||
|
|
||||||
|
@ -362,7 +436,7 @@ struct CmdPrintDevEnv : Common
|
||||||
|
|
||||||
stopProgressBar();
|
stopProgressBar();
|
||||||
|
|
||||||
makeRcScript(buildEnvironment, std::cout);
|
std::cout << makeRcScript(buildEnvironment);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
set -e
|
set -e
|
||||||
if [ -e .attrs.sh ]; then source .attrs.sh; fi
|
if [ -e .attrs.sh ]; then source .attrs.sh; fi
|
||||||
|
|
||||||
outputs=$_outputs_saved
|
|
||||||
for __output in $_outputs_saved; do
|
|
||||||
declare "$__output"="$out"
|
|
||||||
done
|
|
||||||
unset _outputs_saved __output
|
|
||||||
|
|
||||||
export IN_NIX_SHELL=impure
|
export IN_NIX_SHELL=impure
|
||||||
export dontAddDisableDepTrack=1
|
export dontAddDisableDepTrack=1
|
||||||
|
|
||||||
|
@ -14,5 +8,12 @@ if [[ -n $stdenv ]]; then
|
||||||
source $stdenv/setup
|
source $stdenv/setup
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export > $out
|
for __output in $outputs; do
|
||||||
set >> $out
|
if [[ -z $__done ]]; then
|
||||||
|
export > ${!__output}
|
||||||
|
set >> ${!__output}
|
||||||
|
__done=1
|
||||||
|
else
|
||||||
|
echo -n >> ${!__output}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
|
@ -65,7 +65,7 @@ struct NixRepl
|
||||||
void mainLoop(const std::vector<std::string> & files);
|
void mainLoop(const std::vector<std::string> & files);
|
||||||
StringSet completePrefix(string prefix);
|
StringSet completePrefix(string prefix);
|
||||||
bool getLine(string & input, const std::string &prompt);
|
bool getLine(string & input, const std::string &prompt);
|
||||||
Path getDerivationPath(Value & v);
|
StorePath getDerivationPath(Value & v);
|
||||||
bool processLine(string line);
|
bool processLine(string line);
|
||||||
void loadFile(const Path & path);
|
void loadFile(const Path & path);
|
||||||
void initEnv();
|
void initEnv();
|
||||||
|
@ -376,13 +376,16 @@ bool isVarName(const string & s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path NixRepl::getDerivationPath(Value & v) {
|
StorePath NixRepl::getDerivationPath(Value & v) {
|
||||||
auto drvInfo = getDerivation(*state, v, false);
|
auto drvInfo = getDerivation(*state, v, false);
|
||||||
if (!drvInfo)
|
if (!drvInfo)
|
||||||
throw Error("expression does not evaluate to a derivation, so I can't build it");
|
throw Error("expression does not evaluate to a derivation, so I can't build it");
|
||||||
Path drvPath = drvInfo->queryDrvPath();
|
Path drvPathRaw = drvInfo->queryDrvPath();
|
||||||
if (drvPath == "" || !state->store->isValidPath(state->store->parseStorePath(drvPath)))
|
if (drvPathRaw == "")
|
||||||
throw Error("expression did not evaluate to a valid derivation");
|
throw Error("expression did not evaluate to a valid derivation (no drv path)");
|
||||||
|
StorePath drvPath = state->store->parseStorePath(drvPathRaw);
|
||||||
|
if (!state->store->isValidPath(drvPath))
|
||||||
|
throw Error("expression did not evaluate to a valid derivation (invalid drv path)");
|
||||||
return drvPath;
|
return drvPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,29 +479,30 @@ bool NixRepl::processLine(string line)
|
||||||
evalString("drv: (import <nixpkgs> {}).runCommand \"shell\" { buildInputs = [ drv ]; } \"\"", f);
|
evalString("drv: (import <nixpkgs> {}).runCommand \"shell\" { buildInputs = [ drv ]; } \"\"", f);
|
||||||
state->callFunction(f, v, result, Pos());
|
state->callFunction(f, v, result, Pos());
|
||||||
|
|
||||||
Path drvPath = getDerivationPath(result);
|
StorePath drvPath = getDerivationPath(result);
|
||||||
runProgram(settings.nixBinDir + "/nix-shell", Strings{drvPath});
|
runProgram(settings.nixBinDir + "/nix-shell", Strings{state->store->printStorePath(drvPath)});
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (command == ":b" || command == ":i" || command == ":s") {
|
else if (command == ":b" || command == ":i" || command == ":s") {
|
||||||
Value v;
|
Value v;
|
||||||
evalString(arg, v);
|
evalString(arg, v);
|
||||||
Path drvPath = getDerivationPath(v);
|
StorePath drvPath = getDerivationPath(v);
|
||||||
|
Path drvPathRaw = state->store->printStorePath(drvPath);
|
||||||
|
|
||||||
if (command == ":b") {
|
if (command == ":b") {
|
||||||
/* We could do the build in this process using buildPaths(),
|
/* We could do the build in this process using buildPaths(),
|
||||||
but doing it in a child makes it easier to recover from
|
but doing it in a child makes it easier to recover from
|
||||||
problems / SIGINT. */
|
problems / SIGINT. */
|
||||||
if (runProgram(settings.nixBinDir + "/nix", Strings{"build", "--no-link", drvPath}) == 0) {
|
if (runProgram(settings.nixBinDir + "/nix", Strings{"build", "--no-link", drvPathRaw}) == 0) {
|
||||||
auto drv = readDerivation(*state->store, drvPath, Derivation::nameFromPath(state->store->parseStorePath(drvPath)));
|
auto drv = state->store->readDerivation(drvPath);
|
||||||
std::cout << std::endl << "this derivation produced the following outputs:" << std::endl;
|
std::cout << std::endl << "this derivation produced the following outputs:" << std::endl;
|
||||||
for (auto & i : drv.outputsAndPaths(*state->store))
|
for (auto & i : drv.outputsAndPaths(*state->store))
|
||||||
std::cout << fmt(" %s -> %s\n", i.first, state->store->printStorePath(i.second.second));
|
std::cout << fmt(" %s -> %s\n", i.first, state->store->printStorePath(i.second.second));
|
||||||
}
|
}
|
||||||
} else if (command == ":i") {
|
} else if (command == ":i") {
|
||||||
runProgram(settings.nixBinDir + "/nix-env", Strings{"-i", drvPath});
|
runProgram(settings.nixBinDir + "/nix-env", Strings{"-i", drvPathRaw});
|
||||||
} else {
|
} else {
|
||||||
runProgram(settings.nixBinDir + "/nix-shell", Strings{drvPath});
|
runProgram(settings.nixBinDir + "/nix-shell", Strings{drvPathRaw});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue