Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
worker-protocol.hh
Go to the documentation of this file.
1#pragma once
3
5
6namespace nix {
7
8
9#define WORKER_MAGIC_1 0x6e697863
10#define WORKER_MAGIC_2 0x6478696f
11
12// This must remain 1.35 (Nix 2.18) forever in Lix, since the protocol has
13// diverged in CppNix such that we cannot assign newer versions ourselves, the
14// protocol is bad in design and implementation and Lix intends to replace it
15// entirely.
16#define PROTOCOL_VERSION (1 << 8 | 35)
17// Nix 2.3 is protocol 1.21 (see RemoteStore::initConnection for client,
18// processConnection for server).
19#define MIN_SUPPORTED_MINOR_WORKER_PROTO_VERSION 21
20#define MIN_SUPPORTED_WORKER_PROTO_VERSION (1 << 8 | MIN_SUPPORTED_MINOR_WORKER_PROTO_VERSION)
21
22#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
23#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
24
25
26#define REMOVE_AFTER_DROPPING_PROTO_MINOR(protoMinor) \
27 static_assert(MIN_SUPPORTED_MINOR_WORKER_PROTO_VERSION <= (protoMinor))
28
29
30#define STDERR_NEXT 0x6f6c6d67
31#define STDERR_READ 0x64617461 // data needed from source
32#define STDERR_WRITE 0x64617416 // data for sink
33#define STDERR_LAST 0x616c7473
34#define STDERR_ERROR 0x63787470
35#define STDERR_START_ACTIVITY 0x53545254
36#define STDERR_STOP_ACTIVITY 0x53544f50
37#define STDERR_RESULT 0x52534c54
38
39
40class Store;
41struct Source;
42
43// items being serialised
44struct DerivedPath;
45struct BuildResult;
46struct KeyedBuildResult;
47struct ValidPathInfo;
49enum TrustedFlag : bool;
50
51
59{
63 enum struct Op : uint64_t;
64
70 using Version = unsigned int;
71
76 struct ReadConn {
77 Source & from;
78 Version version;
79
80 ReadConn(Source & from, Version version) : from(from), version(version) {
81 assert(version >= MIN_SUPPORTED_WORKER_PROTO_VERSION);
82 }
83 };
84
89 struct WriteConn {
90 Version version;
91
92 explicit WriteConn(Version version) : version(version) {
93 assert(version >= MIN_SUPPORTED_WORKER_PROTO_VERSION);
94 }
95 };
96
103 template<typename T>
104 struct Serialise;
105 // This is the definition of `Serialise` we *want* to put here, but
106 // do not do so.
107 //
108 // The problem is that if we do so, C++ will think we have
109 // seralisers for *all* types. We don't, of course, but that won't
110 // cause an error until link time. That makes for long debug cycles
111 // when there is a missing serialiser.
112 //
113 // By not defining it globally, and instead letting individual
114 // serialisers specialise the type, we get back the compile-time
115 // errors we would like. When no serialiser exists, C++ sees an
116 // abstract "incomplete" type with no definition, and any attempt to
117 // use `to` or `from` static methods is a compile-time error because
118 // they don't exist on an incomplete type.
119 //
120 // This makes for a quicker debug cycle, as desired.
121#if 0
122 {
123 static T read(const Store & store, ReadConn conn);
124 static WireFormatGenerator write(const Store & store, WriteConn conn, const T & t);
125 };
126#endif
127
132 template<typename T>
133 [[nodiscard]]
134 static WireFormatGenerator write(const Store & store, WriteConn conn, const T & t)
135 {
136 return WorkerProto::Serialise<T>::write(store, conn, t);
137 }
138};
139
140enum struct WorkerProto::Op : uint64_t
141{
142 IsValidPath = 1,
143 HasSubstitutes = 3, // obsolete since 2012, stubbed to error
144 QueryPathHash = 4, // obsolete since 2016, stubbed to error
145 QueryReferences = 5, // obsolete since 2016, stubbed to error
146 QueryReferrers = 6,
147 AddToStore = 7,
148 AddTextToStore = 8, // obsolete since protocol 1.25, CppNix 2.4. Use WorkerProto::Op::AddToStore
149 BuildPaths = 9,
150 EnsurePath = 10,
151 AddTempRoot = 11,
152 AddIndirectRoot = 12,
153 SyncWithGC = 13, // obsolete since CppNix 2.5.0
154 FindRoots = 14,
155 ExportPath = 16, // obsolete since 2017, stubbed to error
156 QueryDeriver = 18, // obsolete since 2016, stubbed to error
157 SetOptions = 19,
158 CollectGarbage = 20,
159 QuerySubstitutablePathInfo = 21,
160 QueryDerivationOutputs = 22, // obsolete since protocol 1.21, CppNix 2.4
161 QueryAllValidPaths = 23,
162 QueryFailedPaths = 24, // obsolete, removed
163 ClearFailedPaths = 25, // obsolete, removed
164 QueryPathInfo = 26,
165 ImportPaths = 27, // obsolete since 2016
166 QueryDerivationOutputNames = 28, // obsolete since CppNix 2.4
167 QueryPathFromHashPart = 29,
168 QuerySubstitutablePathInfos = 30,
169 QueryValidPaths = 31,
170 QuerySubstitutablePaths = 32,
171 QueryValidDerivers = 33,
172 OptimiseStore = 34,
173 VerifyStore = 35,
174 BuildDerivation = 36,
175 AddSignatures = 37,
176 NarFromPath = 38,
177 AddToStoreNar = 39,
178 QueryMissing = 40,
179 QueryDerivationOutputMap = 41,
180 RegisterDrvOutput = 42,
181 QueryRealisation = 43,
182 AddMultipleToStore = 44,
183 AddBuildLog = 45,
184 BuildPathsWithResults = 46,
185};
186
193inline Sink & operator << (Sink & sink, WorkerProto::Op op)
194{
195 return sink << (uint64_t) op;
196}
197
203inline std::ostream & operator << (std::ostream & s, WorkerProto::Op op)
204{
205 return s << (uint64_t) op;
206}
207
218#define DECLARE_WORKER_SERIALISER(T) \
219 struct WorkerProto::Serialise< T > \
220 { \
221 static T read(const Store & store, WorkerProto::ReadConn conn); \
222 [[nodiscard]] static WireFormatGenerator write(const Store & store, WorkerProto::WriteConn conn, const T & t); \
223 };
224
225template<>
227template<>
229template<>
231template<>
233template<>
235template<>
236DECLARE_WORKER_SERIALISER(std::optional<TrustedFlag>);
237
238template<typename T>
240template<typename T>
242template<typename... Ts>
243DECLARE_WORKER_SERIALISER(std::tuple<Ts...>);
244
245#define COMMA_ ,
246template<typename K, typename V>
247DECLARE_WORKER_SERIALISER(std::map<K COMMA_ V>);
248#undef COMMA_
249
250}
Definition store-api.hh:195
Definition build-result.hh:17
Definition derived-path.hh:225
Definition build-result.hh:135
Definition serialise.hh:18
Definition serialise.hh:66
Definition path-info.hh:36
Definition path-info.hh:83
Definition worker-protocol.hh:76
Definition worker-protocol.hh:104
Definition worker-protocol.hh:89
Definition worker-protocol.hh:59
unsigned int Version
Definition worker-protocol.hh:70
static WireFormatGenerator write(const Store &store, WriteConn conn, const T &t)
Definition worker-protocol.hh:134
#define DECLARE_WORKER_SERIALISER(T)
Definition worker-protocol.hh:218