Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
worker-protocol.hh
Go to the documentation of this file.
1#pragma once
3
4#include <chrono>
5
6#include "common-protocol.hh"
7
8namespace nix {
9
10
11#define WORKER_MAGIC_1 0x6e697863
12#define WORKER_MAGIC_2 0x6478696f
13
14/* Note: you generally shouldn't change the protocol version. Define a
15 new `WorkerProto::Feature` instead. */
16#define PROTOCOL_VERSION (1 << 8 | 38)
17#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
18#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
19
20
21#define STDERR_NEXT 0x6f6c6d67
22#define STDERR_READ 0x64617461 // data needed from source
23#define STDERR_WRITE 0x64617416 // data for sink
24#define STDERR_LAST 0x616c7473
25#define STDERR_ERROR 0x63787470
26#define STDERR_START_ACTIVITY 0x53545254
27#define STDERR_STOP_ACTIVITY 0x53544f50
28#define STDERR_RESULT 0x52534c54
29
30
31struct StoreDirConfig;
32struct Source;
33
34// items being serialised
35struct DerivedPath;
36struct BuildResult;
37struct KeyedBuildResult;
38struct ValidPathInfo;
40enum BuildMode : uint8_t;
41enum TrustedFlag : bool;
42
43
51{
55 enum struct Op : uint64_t;
56
62 using Version = unsigned int;
63
68 struct ReadConn {
69 Source & from;
70 Version version;
71 };
72
77 struct WriteConn {
78 Sink & to;
79 Version version;
80 };
81
87 struct BasicConnection;
90
95
102 template<typename T>
103 struct Serialise;
104 // This is the definition of `Serialise` we *want* to put here, but
105 // do not do so.
106 //
107 // The problem is that if we do so, C++ will think we have
108 // seralisers for *all* types. We don't, of course, but that won't
109 // cause an error until link time. That makes for long debug cycles
110 // when there is a missing serialiser.
111 //
112 // By not defining it globally, and instead letting individual
113 // serialisers specialise the type, we get back the compile-time
114 // errors we would like. When no serialiser exists, C++ sees an
115 // abstract "incomplete" type with no definition, and any attempt to
116 // use `to` or `from` static methods is a compile-time error because
117 // they don't exist on an incomplete type.
118 //
119 // This makes for a quicker debug cycle, as desired.
120#if 0
121 {
122 static T read(const StoreDirConfig & store, ReadConn conn);
123 static void write(const StoreDirConfig & store, WriteConn conn, const T & t);
124 };
125#endif
126
131 template<typename T>
132 static void write(const StoreDirConfig & store, WriteConn conn, const T & t)
133 {
134 WorkerProto::Serialise<T>::write(store, conn, t);
135 }
136
137 using Feature = std::string;
138
139 static const std::set<Feature> allFeatures;
140};
141
142enum struct WorkerProto::Op : uint64_t
143{
144 IsValidPath = 1,
145 HasSubstitutes = 3,
146 QueryPathHash = 4, // obsolete
147 QueryReferences = 5, // obsolete
148 QueryReferrers = 6,
149 AddToStore = 7,
150 AddTextToStore = 8, // obsolete since 1.25, Nix 3.0. Use WorkerProto::Op::AddToStore
151 BuildPaths = 9,
152 EnsurePath = 10,
153 AddTempRoot = 11,
154 AddIndirectRoot = 12,
155 SyncWithGC = 13,
156 FindRoots = 14,
157 ExportPath = 16, // obsolete
158 QueryDeriver = 18, // obsolete
159 SetOptions = 19,
160 CollectGarbage = 20,
161 QuerySubstitutablePathInfo = 21,
162 QueryDerivationOutputs = 22, // obsolete
163 QueryAllValidPaths = 23,
164 QueryFailedPaths = 24,
165 ClearFailedPaths = 25,
166 QueryPathInfo = 26,
167 ImportPaths = 27, // obsolete
168 QueryDerivationOutputNames = 28, // obsolete
169 QueryPathFromHashPart = 29,
170 QuerySubstitutablePathInfos = 30,
171 QueryValidPaths = 31,
172 QuerySubstitutablePaths = 32,
173 QueryValidDerivers = 33,
174 OptimiseStore = 34,
175 VerifyStore = 35,
176 BuildDerivation = 36,
177 AddSignatures = 37,
178 NarFromPath = 38,
179 AddToStoreNar = 39,
180 QueryMissing = 40,
181 QueryDerivationOutputMap = 41,
182 RegisterDrvOutput = 42,
183 QueryRealisation = 43,
184 AddMultipleToStore = 44,
185 AddBuildLog = 45,
186 BuildPathsWithResults = 46,
187 AddPermRoot = 47,
188};
189
191{
198 std::optional<std::string> daemonNixVersion;
199
211 std::optional<TrustedFlag> remoteTrustsUs;
212
213 bool operator == (const ClientHandshakeInfo &) const = default;
214};
215
222inline Sink & operator << (Sink & sink, WorkerProto::Op op)
223{
224 return sink << static_cast<uint64_t>(op);
225}
226
232inline std::ostream & operator << (std::ostream & s, WorkerProto::Op op)
233{
235}
236
247#define DECLARE_WORKER_SERIALISER(T) \
248 struct WorkerProto::Serialise< T > \
249 { \
250 static T read(const StoreDirConfig & store, WorkerProto::ReadConn conn); \
251 static void write(const StoreDirConfig & store, WorkerProto::WriteConn conn, const T & t); \
252 };
253
254template<>
256template<>
258template<>
260template<>
262template<>
264template<>
266template<>
267DECLARE_WORKER_SERIALISER(std::optional<TrustedFlag>);
268template<>
269DECLARE_WORKER_SERIALISER(std::optional<std::chrono::microseconds>);
270template<>
272
273template<typename T>
275template<typename T>
277template<typename... Ts>
278DECLARE_WORKER_SERIALISER(std::tuple<Ts...>);
279
280#define COMMA_ ,
281template<typename K, typename V>
282DECLARE_WORKER_SERIALISER(std::map<K COMMA_ V>);
283#undef COMMA_
284
285}
ChunkedVector< std::string, 8192 > store
Definition lexer.l:1011
return s
Definition lexer.l:459
int
Definition lexer.l:2928
T t
Definition lexer.l:154
Definition build-result.hh:14
Definition derived-path.hh:229
Definition build-result.hh:121
Definition serialise.hh:20
Definition serialise.hh:68
Definition store-dir-config.hh:22
Definition path-info.hh:42
Definition path-info.hh:130
Definition worker-protocol-connection.hh:65
Definition worker-protocol-connection.hh:10
Definition worker-protocol-connection.hh:140
Definition worker-protocol.hh:191
std::optional< std::string > daemonNixVersion
Definition worker-protocol.hh:198
std::optional< TrustedFlag > remoteTrustsUs
Definition worker-protocol.hh:211
Definition worker-protocol.hh:68
Definition worker-protocol-impl.hh:42
Definition worker-protocol.hh:77
Definition worker-protocol.hh:51
unsigned int Version
Definition worker-protocol.hh:62
static void write(const StoreDirConfig &store, WriteConn conn, const T &t)
Definition worker-protocol.hh:132
#define DECLARE_WORKER_SERIALISER(T)
Definition worker-protocol.hh:247