Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
serve-protocol.hh
Go to the documentation of this file.
1#pragma once
3
5
6namespace nix {
7
8#define SERVE_MAGIC_1 0x390c9deb
9#define SERVE_MAGIC_2 0x5452eecb
10
11#define SERVE_PROTOCOL_VERSION (2 << 8 | 8)
12#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
13#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
14struct StoreDirConfig;
15struct Source;
16
17// items being serialised
18struct BuildResult;
20struct DrvOutput;
22struct Realisation;
23
31{
35 enum struct Command : uint64_t;
36
42 struct Version
43 {
44 unsigned int major;
45 uint8_t minor;
46
47 constexpr auto operator<=>(const Version &) const = default;
48
53 constexpr unsigned int toWire() const
54 {
55 return (major << 8) | minor;
56 }
57
61 static constexpr Version fromWire(unsigned int wire)
62 {
63 return {
64 .major = (wire & 0xff00) >> 8,
65 .minor = static_cast<uint8_t>(wire & 0x00ff),
66 };
67 }
68 };
69
70 static constexpr Version latest = {
71 .major = 2,
72 .minor = 8,
73 };
74
79 struct ReadConn
80 {
81 Source & from;
82 Version version;
83 };
84
89 struct WriteConn
90 {
91 Sink & to;
92 Version version;
93 };
94
102
109 template<typename T>
110 struct Serialise;
111 // This is the definition of `Serialise` we *want* to put here, but
112 // do not do so.
113 //
114 // See `worker-protocol.hh` for a longer explanation.
115#if 0
116 {
117 static T read(const StoreDirConfig & store, ReadConn conn);
118 static void write(const StoreDirConfig & store, WriteConn conn, const T & t);
119 };
120#endif
121
126 template<typename T>
127 static void write(const StoreDirConfig & store, WriteConn conn, const T & t)
128 {
129 ServeProto::Serialise<T>::write(store, conn, t);
130 }
131
137 struct BuildOptions;
138};
139
140enum struct ServeProto::Command : uint64_t {
141 QueryValidPaths = 1,
142 QueryPathInfos = 2,
143 DumpStorePath = 3,
149 ImportPaths = 4,
150 // ExportPaths = 5,
151 BuildPaths = 6,
152 QueryClosure = 7,
153 BuildDerivation = 8,
154 AddToStoreNar = 9,
155};
156
158{
163 time_t maxSilentTime = -1;
164 time_t buildTimeout = -1;
165 size_t maxLogSize = -1;
166 size_t nrRepeats = -1;
167 bool enforceDeterminism = -1;
168 bool keepFailed = -1;
169
170 bool operator==(const ServeProto::BuildOptions &) const = default;
171};
172
179inline Sink & operator<<(Sink & sink, ServeProto::Command op)
180{
181 return sink << (uint64_t) op;
182}
183
189inline std::ostream & operator<<(std::ostream & s, ServeProto::Command op)
190{
191 return s << (uint64_t) op;
192}
193
204#define DECLARE_SERVE_SERIALISER(T) \
205 struct ServeProto::Serialise<T> \
206 { \
207 static T read(const StoreDirConfig & store, ServeProto::ReadConn conn); \
208 static void write(const StoreDirConfig & store, ServeProto::WriteConn conn, const T & t); \
209 };
210
211template<>
213template<>
215template<>
217template<>
219template<>
221template<>
223
224template<typename T>
226#define COMMA_ ,
227template<typename T, typename Compare>
228DECLARE_SERVE_SERIALISER(std::set<T COMMA_ Compare>);
229template<typename... Ts>
230DECLARE_SERVE_SERIALISER(std::tuple<Ts...>);
231
232template<typename K, typename V, typename Compare>
233DECLARE_SERVE_SERIALISER(std::map<K COMMA_ V COMMA_ Compare>);
234#undef COMMA_
235
236} // namespace nix
size_t read(Descriptor fd, std::span< std::byte > buffer)
Definition file-descriptor.cc:30
#define DECLARE_SERVE_SERIALISER(T)
Definition serve-protocol.hh:204
Definition build-result.hh:123
Definition realisation.hh:26
Definition realisation.hh:103
Definition serve-protocol-connection.hh:10
Definition serve-protocol-connection.hh:90
Definition serve-protocol.hh:158
time_t maxSilentTime
Definition serve-protocol.hh:163
Definition serve-protocol.hh:80
Definition serve-protocol-impl.hh:47
Definition serve-protocol.hh:43
constexpr unsigned int toWire() const
Definition serve-protocol.hh:53
static constexpr Version fromWire(unsigned int wire)
Definition serve-protocol.hh:61
Definition serve-protocol.hh:90
Definition serve-protocol.hh:31
static void write(const StoreDirConfig &store, WriteConn conn, const T &t)
Definition serve-protocol.hh:127
Command
Definition serve-protocol.hh:140
Definition serialise.hh:18
Definition serialise.hh:95
Definition store-dir-config.hh:29
Definition realisation.hh:62
Definition path-info.hh:58