Skip to content

Commit afcce6f

Browse files
authored
Merge pull request #13 from DeterminateSystems/logger-improvements
Logger improvements
2 parents aa9d573 + 10f9b2f commit afcce6f

20 files changed

+369
-31
lines changed

doc/manual/source/SUMMARY.md.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
- [Determinate Nix Release Notes](release-notes-determinate/index.md)
130130
- [Changes between Nix and Determinate Nix](release-notes-determinate/changes.md)
131131
- [Release 3.0.0 (2025-03-04)](release-notes-determinate/rl-3.0.0.md)
132-
- [Release 3.1.0 (2025-??-??)](release-notes-determinate/rl-3.1.0.md)
132+
- [Release 3.1.0 (2025-03-27)](release-notes-determinate/rl-3.1.0.md)
133133
- [Nix Release Notes](release-notes/index.md)
134134
{{#include ./SUMMARY-rl-next.md}}
135135
- [Release 2.27 (2025-03-03)](release-notes/rl-2.27.md)

doc/manual/source/release-notes-determinate/changes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ This section lists the differences between upstream Nix 2.24 and Determinate Nix
55
* In Determinate Nix, flakes are stable. You no longer need to enable the `flakes` experimental feature.
66

77
* In Determinate Nix, the new Nix CLI (i.e. the `nix` command) is stable. You no longer need to enable the `nix-command` experimental feature.
8+
9+
* Determinate Nix has a setting [`json-log-path`](@docroot@/command-ref/conf-file.md#conf-json-log-path) to send a copy of all Nix log messages (in JSON format) to a file or Unix domain socket.

doc/manual/source/release-notes-determinate/rl-3.0.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
* Initial release of Determinate Nix.
44

55
* Based on [upstream Nix 2.26.2](../release-notes/rl-2.26.md).
6+
7+
* New setting `json-log-path` that sends a copy of all Nix log messages (in JSON format) to a file or Unix domain socket.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Release 3.1.0 (2025-??-??)
1+
# Release 3.1.0 (2025-03-27)
22

33
* Based on [upstream Nix 2.27.1](../release-notes/rl-2.27.md).

src/libstore/build-result.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,49 @@
11
#include "build-result.hh"
22

3+
#include <nlohmann/json.hpp>
4+
35
namespace nix {
46

57
bool BuildResult::operator==(const BuildResult &) const noexcept = default;
68
std::strong_ordering BuildResult::operator<=>(const BuildResult &) const noexcept = default;
79

10+
void to_json(nlohmann::json & json, const BuildResult & buildResult)
11+
{
12+
json = nlohmann::json::object();
13+
json["status"] = BuildResult::statusToString(buildResult.status);
14+
if (buildResult.errorMsg != "")
15+
json["errorMsg"] = buildResult.errorMsg;
16+
if (buildResult.timesBuilt)
17+
json["timesBuilt"] = buildResult.timesBuilt;
18+
if (buildResult.isNonDeterministic)
19+
json["isNonDeterministic"] = buildResult.isNonDeterministic;
20+
if (buildResult.startTime)
21+
json["startTime"] = buildResult.startTime;
22+
if (buildResult.stopTime)
23+
json["stopTime"] = buildResult.stopTime;
24+
}
25+
26+
void to_json(nlohmann::json & json, const KeyedBuildResult & buildResult)
27+
{
28+
to_json(json, (const BuildResult &) buildResult);
29+
auto path = nlohmann::json::object();
30+
std::visit(
31+
overloaded{
32+
[&](const DerivedPathOpaque & opaque) { path["opaque"] = opaque.path.to_string(); },
33+
[&](const DerivedPathBuilt & drv) {
34+
path["drvPath"] = drv.drvPath->getBaseStorePath().to_string();
35+
path["outputs"] = drv.outputs;
36+
auto outputs = nlohmann::json::object();
37+
for (auto & [name, output] : buildResult.builtOutputs)
38+
outputs[name] = {
39+
{"path", output.outPath.to_string()},
40+
{"signatures", output.signatures},
41+
};
42+
json["builtOutputs"] = std::move(outputs);
43+
},
44+
},
45+
buildResult.path.raw());
46+
json["path"] = std::move(path);
47+
}
48+
849
}

src/libstore/build-result.hh

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <chrono>
99
#include <optional>
1010

11+
#include <nlohmann/json_fwd.hpp>
12+
1113
namespace nix {
1214

1315
struct BuildResult
@@ -46,28 +48,32 @@ struct BuildResult
4648
*/
4749
std::string errorMsg;
4850

51+
static std::string_view statusToString(Status status)
52+
{
53+
switch (status) {
54+
case Built: return "Built";
55+
case Substituted: return "Substituted";
56+
case AlreadyValid: return "AlreadyValid";
57+
case PermanentFailure: return "PermanentFailure";
58+
case InputRejected: return "InputRejected";
59+
case OutputRejected: return "OutputRejected";
60+
case TransientFailure: return "TransientFailure";
61+
case CachedFailure: return "CachedFailure";
62+
case TimedOut: return "TimedOut";
63+
case MiscFailure: return "MiscFailure";
64+
case DependencyFailed: return "DependencyFailed";
65+
case LogLimitExceeded: return "LogLimitExceeded";
66+
case NotDeterministic: return "NotDeterministic";
67+
case ResolvesToAlreadyValid: return "ResolvesToAlreadyValid";
68+
case NoSubstituters: return "NoSubstituters";
69+
default: return "Unknown";
70+
};
71+
}
72+
4973
std::string toString() const {
50-
auto strStatus = [&]() {
51-
switch (status) {
52-
case Built: return "Built";
53-
case Substituted: return "Substituted";
54-
case AlreadyValid: return "AlreadyValid";
55-
case PermanentFailure: return "PermanentFailure";
56-
case InputRejected: return "InputRejected";
57-
case OutputRejected: return "OutputRejected";
58-
case TransientFailure: return "TransientFailure";
59-
case CachedFailure: return "CachedFailure";
60-
case TimedOut: return "TimedOut";
61-
case MiscFailure: return "MiscFailure";
62-
case DependencyFailed: return "DependencyFailed";
63-
case LogLimitExceeded: return "LogLimitExceeded";
64-
case NotDeterministic: return "NotDeterministic";
65-
case ResolvesToAlreadyValid: return "ResolvesToAlreadyValid";
66-
case NoSubstituters: return "NoSubstituters";
67-
default: return "Unknown";
68-
};
69-
}();
70-
return strStatus + ((errorMsg == "") ? "" : " : " + errorMsg);
74+
return
75+
std::string(statusToString(status))
76+
+ ((errorMsg == "") ? "" : " : " + errorMsg);
7177
}
7278

7379
/**
@@ -130,4 +136,7 @@ struct KeyedBuildResult : BuildResult
130136
{ }
131137
};
132138

139+
void to_json(nlohmann::json & json, const BuildResult & buildResult);
140+
void to_json(nlohmann::json & json, const KeyedBuildResult & buildResult);
141+
133142
}

src/libstore/build/derivation-goal.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,14 @@ Goal::Done DerivationGoal::done(
15401540
fs << worker.store.printStorePath(drvPath) << "\t" << buildResult.toString() << std::endl;
15411541
}
15421542

1543+
logger->result(
1544+
act ? act->id : getCurActivity(),
1545+
resBuildResult,
1546+
nlohmann::json(
1547+
KeyedBuildResult(
1548+
buildResult,
1549+
DerivedPath::Built{.drvPath = makeConstantStorePathRef(drvPath), .outputs = wantedOutputs})));
1550+
15431551
return amDone(buildResult.success() ? ecSuccess : ecFailed, std::move(ex));
15441552
}
15451553

src/libstore/build/substitution-goal.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
#include "nar-info.hh"
44
#include "finally.hh"
55
#include "signals.hh"
6+
67
#include <coroutine>
78

9+
#include <nlohmann/json.hpp>
10+
811
namespace nix {
912

1013
PathSubstitutionGoal::PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair, std::optional<ContentAddress> ca)
@@ -35,6 +38,15 @@ Goal::Done PathSubstitutionGoal::done(
3538
debug(*errorMsg);
3639
buildResult.errorMsg = *errorMsg;
3740
}
41+
42+
logger->result(
43+
getCurActivity(),
44+
resBuildResult,
45+
nlohmann::json(
46+
KeyedBuildResult(
47+
buildResult,
48+
DerivedPath::Opaque{storePath})));
49+
3850
return amDone(result);
3951
}
4052

src/libstore/daemon.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "derivations.hh"
1616
#include "args.hh"
1717
#include "git.hh"
18+
#include "logging.hh"
1819

1920
#ifndef _WIN32 // TODO need graceful async exit support on Windows?
2021
# include "monitor-fd.hh"
@@ -1049,6 +1050,7 @@ void processConnection(
10491050
if (!recursive) {
10501051
prevLogger_ = std::move(logger);
10511052
logger = std::move(tunnelLogger_);
1053+
applyJSONLogger();
10521054
}
10531055

10541056
unsigned int opCount = 0;

src/libstore/uds-remote-store.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
8484
auto conn = make_ref<Connection>();
8585

8686
/* Connect to a daemon that does the privileged work for us. */
87-
conn->fd = createUnixDomainSocket();
88-
89-
nix::connect(toSocket(conn->fd.get()), path);
87+
conn->fd = nix::connect(path);
9088

9189
conn->from.fd = conn->fd.get();
9290
conn->to.fd = conn->fd.get();

0 commit comments

Comments
 (0)