Skip to content

Commit a511f44

Browse files
committed
Marshal lastUsageTime over worker protocol
Serialize the lastUsageTime path info attribute as part of the worker protocol, making it accessible to e.g. non-root users using the nix daemon. This is accomplished using a new fine-grained worker protocol feature, along with some additional plumbing to make the set of negotiated features accessible to the serializer code.
1 parent de98d8f commit a511f44

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

src/libstore/include/nix/store/worker-protocol-connection.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct WorkerProto::BasicConnection
4141
return WorkerProto::ReadConn{
4242
.from = from,
4343
.version = protoVersion,
44+
.features = &features,
4445
};
4546
}
4647

@@ -57,6 +58,7 @@ struct WorkerProto::BasicConnection
5758
return WorkerProto::WriteConn{
5859
.to = to,
5960
.version = protoVersion,
61+
.features = &features,
6062
};
6163
}
6264
};

src/libstore/include/nix/store/worker-protocol.hh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ struct WorkerProto
5858
*/
5959
using Version = unsigned int;
6060

61+
using Feature = std::string;
62+
using FeatureSet = std::set<Feature, std::less<>>;
63+
64+
static const FeatureSet allFeatures;
65+
6166
/**
6267
* A unidirectional read connection, to be used by the read half of the
6368
* canonical serializers below.
@@ -66,6 +71,7 @@ struct WorkerProto
6671
{
6772
Source & from;
6873
Version version;
74+
const FeatureSet * features{nullptr};
6975
};
7076

7177
/**
@@ -76,6 +82,7 @@ struct WorkerProto
7682
{
7783
Sink & to;
7884
Version version;
85+
const FeatureSet * features{nullptr};
7986
};
8087

8188
/**
@@ -132,11 +139,6 @@ struct WorkerProto
132139
{
133140
WorkerProto::Serialise<T>::write(store, conn, t);
134141
}
135-
136-
using Feature = std::string;
137-
using FeatureSet = std::set<Feature, std::less<>>;
138-
139-
static const FeatureSet allFeatures;
140142
};
141143

142144
enum struct WorkerProto::Op : uint64_t {

src/libstore/worker-protocol-connection.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace nix {
77

8-
const WorkerProto::FeatureSet WorkerProto::allFeatures{};
8+
const WorkerProto::FeatureSet WorkerProto::allFeatures{"path-last-usage-time"};
99

1010
WorkerProto::BasicClientConnection::~BasicClientConnection()
1111
{

src/libstore/worker-protocol.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ UnkeyedValidPathInfo WorkerProto::Serialise<UnkeyedValidPathInfo>::read(const St
262262
info.sigs = readStrings<StringSet>(conn.from);
263263
info.ca = ContentAddress::parseOpt(readString(conn.from));
264264
}
265+
if (conn.features && conn.features->contains("last-usage-time")) {
266+
conn.from >> info.lastUsageTime;
267+
}
265268
return info;
266269
}
267270

@@ -275,6 +278,9 @@ void WorkerProto::Serialise<UnkeyedValidPathInfo>::write(
275278
if (GET_PROTOCOL_MINOR(conn.version) >= 16) {
276279
conn.to << pathInfo.ultimate << pathInfo.sigs << renderContentAddress(pathInfo.ca);
277280
}
281+
if (conn.features && conn.features->contains("last-usage-time")) {
282+
conn.to << pathInfo.lastUsageTime;
283+
}
278284
}
279285

280286
WorkerProto::ClientHandshakeInfo

0 commit comments

Comments
 (0)