Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
serve-protocol.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include "
nix/store/common-protocol.hh
"
5
6
namespace
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)
14
struct
StoreDirConfig
;
15
struct
Source
;
16
17
// items being serialised
18
struct
BuildResult
;
19
struct
UnkeyedValidPathInfo
;
20
struct
DrvOutput
;
21
struct
UnkeyedRealisation
;
22
struct
Realisation
;
23
30
struct
ServeProto
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
100
struct
BasicClientConnection
;
101
struct
BasicServerConnection
;
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
140
enum 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
157
struct
ServeProto::BuildOptions
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
179
inline
Sink
& operator<<(
Sink
& sink,
ServeProto::Command
op)
180
{
181
return
sink << (uint64_t) op;
182
}
183
189
inline
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
211
template
<>
212
DECLARE_SERVE_SERIALISER
(
BuildResult
);
213
template
<>
214
DECLARE_SERVE_SERIALISER
(
DrvOutput
);
215
template
<>
216
DECLARE_SERVE_SERIALISER
(
UnkeyedRealisation
);
217
template
<>
218
DECLARE_SERVE_SERIALISER
(
Realisation
);
219
template
<>
220
DECLARE_SERVE_SERIALISER
(
UnkeyedValidPathInfo
);
221
template
<>
222
DECLARE_SERVE_SERIALISER
(
ServeProto::BuildOptions
);
223
224
template
<
typename
T>
225
DECLARE_SERVE_SERIALISER
(std::vector<T>);
226
#define COMMA_ ,
227
template
<
typename
T,
typename
Compare>
228
DECLARE_SERVE_SERIALISER
(std::set<T COMMA_ Compare>);
229
template
<
typename
... Ts>
230
DECLARE_SERVE_SERIALISER
(std::tuple<Ts...>);
231
232
template
<
typename
K,
typename
V,
typename
Compare>
233
DECLARE_SERVE_SERIALISER
(std::map<K COMMA_ V COMMA_ Compare>);
234
#undef COMMA_
235
236
}
// namespace nix
common-protocol.hh
nix::read
size_t read(Descriptor fd, std::span< std::byte > buffer)
Definition
file-descriptor.cc:30
DECLARE_SERVE_SERIALISER
#define DECLARE_SERVE_SERIALISER(T)
Definition
serve-protocol.hh:204
nix::BuildResult
Definition
build-result.hh:123
nix::DrvOutput
Definition
realisation.hh:26
nix::Realisation
Definition
realisation.hh:103
nix::ServeProto::BasicClientConnection
Definition
serve-protocol-connection.hh:10
nix::ServeProto::BasicServerConnection
Definition
serve-protocol-connection.hh:90
nix::ServeProto::BuildOptions
Definition
serve-protocol.hh:158
nix::ServeProto::BuildOptions::maxSilentTime
time_t maxSilentTime
Definition
serve-protocol.hh:163
nix::ServeProto::ReadConn
Definition
serve-protocol.hh:80
nix::ServeProto::Serialise
Definition
serve-protocol-impl.hh:47
nix::ServeProto::Version
Definition
serve-protocol.hh:43
nix::ServeProto::Version::toWire
constexpr unsigned int toWire() const
Definition
serve-protocol.hh:53
nix::ServeProto::Version::fromWire
static constexpr Version fromWire(unsigned int wire)
Definition
serve-protocol.hh:61
nix::ServeProto::WriteConn
Definition
serve-protocol.hh:90
nix::ServeProto
Definition
serve-protocol.hh:31
nix::ServeProto::write
static void write(const StoreDirConfig &store, WriteConn conn, const T &t)
Definition
serve-protocol.hh:127
nix::ServeProto::Command
Command
Definition
serve-protocol.hh:140
nix::Sink
Definition
serialise.hh:18
nix::Source
Definition
serialise.hh:95
nix::StoreDirConfig
Definition
store-dir-config.hh:29
nix::UnkeyedRealisation
Definition
realisation.hh:62
nix::UnkeyedValidPathInfo
Definition
path-info.hh:58
libstore
include
nix
store
serve-protocol.hh
Generated by
1.18.0