Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
remote-store.hh
Go to the documentation of this file.
1#pragma once
3
4#include <limits>
5#include <string>
6#include <utility>
7
13#include "lix/libutil/types.hh"
14
15
16namespace nix {
17
18
19class Pipe;
20class Pid;
21struct FdSink;
22struct FdSource;
23template<typename T> class Pool;
24
25struct RemoteStoreConfig : virtual StoreConfig
26{
27 using StoreConfig::StoreConfig;
28
29 const Setting<int> maxConnections{this, 1, "max-connections",
30 "Maximum number of concurrent connections to the Nix daemon."};
31
32 const Setting<unsigned int> maxConnectionAge{this,
33 std::numeric_limits<unsigned int>::max(),
34 "max-connection-age",
35 "Maximum age of a connection before it is closed."};
36};
37
42class RemoteStore : public virtual Store,
43 public virtual GcStore,
44 public virtual LogStore
45{
46public:
47
48 RemoteStore(const RemoteStoreConfig & config);
49
50 RemoteStoreConfig & config() override = 0;
51 const RemoteStoreConfig & config() const override = 0;
52
53 /* Implementations of abstract store API methods. */
54
55 kj::Promise<Result<bool>> isValidPathUncached(const StorePath & path) override;
56
57 kj::Promise<Result<StorePathSet>> queryValidPaths(const StorePathSet & paths,
58 SubstituteFlag maybeSubstitute = NoSubstitute) override;
59
60 kj::Promise<Result<StorePathSet>> queryAllValidPaths() override;
61
62 kj::Promise<Result<std::shared_ptr<const ValidPathInfo>>>
63 queryPathInfoUncached(const StorePath & path) override;
64
65 kj::Promise<Result<void>>
66 queryReferrers(const StorePath & path, StorePathSet & referrers) override;
67
68 kj::Promise<Result<StorePathSet>> queryValidDerivers(const StorePath & path) override;
69
70 kj::Promise<Result<StorePathSet>> queryDerivationOutputs(const StorePath & path) override;
71
72 kj::Promise<Result<std::map<std::string, std::optional<StorePath>>>>
73 queryPartialDerivationOutputMap(const StorePath & path, Store * evalStore = nullptr) override;
74 kj::Promise<Result<std::optional<StorePath>>>
75 queryPathFromHashPart(const std::string & hashPart) override;
76
77 kj::Promise<Result<StorePathSet>> querySubstitutablePaths(const StorePathSet & paths) override;
78
79 kj::Promise<Result<void>> querySubstitutablePathInfos(const StorePathCAMap & paths,
80 SubstitutablePathInfos & infos) override;
81
85 kj::Promise<Result<ref<const ValidPathInfo>>> addCAToStore(
86 AsyncInputStream & dump,
87 std::string_view name,
88 ContentAddressMethod caMethod,
89 HashType hashType,
90 const StorePathSet & references,
91 RepairFlag repair);
92
96 kj::Promise<Result<StorePath>> addToStoreFromDump(
97 AsyncInputStream & dump,
98 std::string_view name,
100 HashType hashAlgo = HashType::SHA256,
101 RepairFlag repair = NoRepair,
102 const StorePathSet & references = StorePathSet()
103 ) override;
104
105 kj::Promise<Result<void>> addToStore(const ValidPathInfo & info, AsyncInputStream & nar,
106 RepairFlag repair, CheckSigsFlag checkSigs) override;
107
108 kj::Promise<Result<void>> addMultipleToStore(
109 PathsSource & pathsToCopy,
110 Activity & act,
111 RepairFlag repair,
112 CheckSigsFlag checkSigs) override;
113
114 kj::Promise<Result<StorePath>> addTextToStore(
115 std::string_view name,
116 std::string_view s,
117 const StorePathSet & references,
118 RepairFlag repair) override;
119
120 kj::Promise<Result<void>> registerDrvOutput(const Realisation & info) override;
121
122 kj::Promise<Result<std::shared_ptr<const Realisation>>>
123 queryRealisationUncached(const DrvOutput &) override;
124
125 kj ::Promise<Result<void>> buildPaths(
126 const std::vector<DerivedPath> & paths,
127 BuildMode buildMode,
128 std::shared_ptr<Store> evalStore
129 ) override;
130
131 kj::Promise<Result<std::vector<KeyedBuildResult>>> buildPathsWithResults(
132 const std::vector<DerivedPath> & paths,
133 BuildMode buildMode,
134 std::shared_ptr<Store> evalStore) override;
135
136 kj ::Promise<Result<BuildResult>> buildDerivation(
137 const StorePath & drvPath, const BasicDerivation & drv, BuildMode buildMode
138 ) override;
139
140 kj::Promise<Result<void>> ensurePath(const StorePath & path) override;
141
142 kj::Promise<Result<void>> addTempRoot(const StorePath & path) override;
143
144 kj::Promise<Result<Roots>> findRoots(bool censor) override;
145
146 kj::Promise<Result<void>>
147 collectGarbage(const GCOptions & options, GCResults & results) override;
148
149 kj::Promise<Result<void>> optimiseStore() override;
150
151 kj::Promise<Result<bool>> verifyStore(bool checkContents, RepairFlag repair) override;
152
161 kj::Promise<Result<void>> repairPath(const StorePath & path) override
162 try { unsupported("repairPath"); } catch (...) { return {result::current_exception()}; }
163
164 kj::Promise<Result<void>>
165 addSignatures(const StorePath & storePath, const StringSet & sigs) override;
166
167 kj::Promise<Result<void>> queryMissing(const std::vector<DerivedPath> & targets,
168 StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown,
169 uint64_t & downloadSize, uint64_t & narSize) override;
170
171 kj::Promise<Result<void>> addBuildLog(const StorePath & drvPath, std::string_view log) override;
172
173 kj::Promise<Result<std::optional<std::string>>> getVersion() override;
174
175 kj::Promise<Result<void>> connect() override;
176
177 kj::Promise<Result<unsigned int>> getProtocol() override;
178
179 kj::Promise<Result<std::optional<TrustedFlag>>> isTrustedClient() override;
180
181 struct Connection;
182
183 ref<Connection> openConnectionWrapper();
184
185protected:
186
187 virtual ref<Connection> openConnection() = 0;
188
189 void initConnection(Connection & conn);
190
191 ref<Pool<Connection>> connections;
192
193 virtual void setOptions(Connection & conn);
194
195 kj::Promise<Result<void>> setOptions() override;
196
197 struct ConnectionHandle;
198
199 kj::Promise<Result<ConnectionHandle>> getConnection();
200
201 friend struct ConnectionHandle;
202
203 virtual ref<FSAccessor> getFSAccessor() override;
204
205 virtual kj::Promise<Result<box_ptr<Source>>> narFromPath(const StorePath & path) override;
206
207private:
208
209 std::atomic_bool failed{false};
210
211 // NOTE we rely on the thread pool not starting threads eagerly. if it ever starts
212 // doing that we're certainly going to fail due to the immense thread count, which
213 // we need to satisfy temporary `incCapacity` calls by some RemoteStore functions.
214 Sync<ThreadPool> handlerThreads{
215 std::in_place, "remote stderr", std::numeric_limits<size_t>::max()
216 };
217
218 kj::Promise<Result<void>> copyDrvsFromEvalStore(
219 const std::vector<DerivedPath> & paths,
220 std::shared_ptr<Store> evalStore);
221};
222
223}
Definition async-io.hh:19
Definition processes.hh:24
Definition file-descriptor.hh:79
Definition pool.hh:40
kj::Promise< Result< void > > queryMissing(const std::vector< DerivedPath > &targets, StorePathSet &willBuild, StorePathSet &willSubstitute, StorePathSet &unknown, uint64_t &downloadSize, uint64_t &narSize) override
Definition remote-store.cc:934
virtual ref< FSAccessor > getFSAccessor() override
Definition remote-store.cc:1024
kj::Promise< Result< StorePath > > addTextToStore(std::string_view name, std::string_view s, const StorePathSet &references, RepairFlag repair) override
Definition remote-store.cc:611
kj::Promise< Result< void > > connect() override
Definition remote-store.cc:976
kj::Promise< Result< void > > addToStore(const ValidPathInfo &info, AsyncInputStream &nar, RepairFlag repair, CheckSigsFlag checkSigs) override
Definition remote-store.cc:529
kj::Promise< Result< void > > querySubstitutablePathInfos(const StorePathCAMap &paths, SubstitutablePathInfos &infos) override
Definition remote-store.cc:260
kj::Promise< Result< void > > queryReferrers(const StorePath &path, StorePathSet &referrers) override
Definition remote-store.cc:318
kj::Promise< Result< StorePathSet > > queryAllValidPaths() override
Definition remote-store.cc:237
kj ::Promise< Result< void > > buildPaths(const std::vector< DerivedPath > &paths, BuildMode buildMode, std::shared_ptr< Store > evalStore) override
Definition remote-store.cc:698
kj::Promise< Result< void > > addTempRoot(const StorePath &path) override
Definition remote-store.cc:839
kj::Promise< Result< void > > setOptions() override
Definition remote-store.cc:202
kj::Promise< Result< Roots > > findRoots(bool censor) override
Definition remote-store.cc:851
kj::Promise< Result< unsigned int > > getProtocol() override
Definition remote-store.cc:985
kj::Promise< Result< void > > ensurePath(const StorePath &path) override
Definition remote-store.cc:827
kj::Promise< Result< void > > repairPath(const StorePath &path) override
Definition remote-store.hh:161
kj::Promise< Result< void > > addMultipleToStore(PathsSource &pathsToCopy, Activity &act, RepairFlag repair, CheckSigsFlag checkSigs) override
Definition remote-store.cc:570
kj::Promise< Result< StorePathSet > > queryValidPaths(const StorePathSet &paths, SubstituteFlag maybeSubstitute=NoSubstitute) override
Definition remote-store.cc:222
kj ::Promise< Result< BuildResult > > buildDerivation(const StorePath &drvPath, const BasicDerivation &drv, BuildMode buildMode) override
Definition remote-store.cc:812
virtual kj::Promise< Result< box_ptr< Source > > > narFromPath(const StorePath &path) override
Definition remote-store.cc:1011
kj::Promise< Result< bool > > verifyStore(bool checkContents, RepairFlag repair) override
Definition remote-store.cc:910
kj::Promise< Result< void > > registerDrvOutput(const Realisation &info) override
Definition remote-store.cc:623
kj::Promise< Result< StorePathSet > > querySubstitutablePaths(const StorePathSet &paths) override
Definition remote-store.cc:248
kj::Promise< Result< std::optional< TrustedFlag > > > isTrustedClient() override
Definition remote-store.cc:993
kj::Promise< Result< void > > optimiseStore() override
Definition remote-store.cc:898
kj::Promise< Result< std::shared_ptr< const ValidPathInfo > > > queryPathInfoUncached(const StorePath &path) override
Definition remote-store.cc:294
kj::Promise< Result< void > > addSignatures(const StorePath &storePath, const StringSet &sigs) override
Definition remote-store.cc:922
kj::Promise< Result< StorePath > > addToStoreFromDump(AsyncInputStream &dump, std::string_view name, FileIngestionMethod method=FileIngestionMethod::Recursive, HashType hashAlgo=HashType::SHA256, RepairFlag repair=NoRepair, const StorePathSet &references=StorePathSet()) override
Definition remote-store.cc:514
kj::Promise< Result< ref< const ValidPathInfo > > > addCAToStore(AsyncInputStream &dump, std::string_view name, ContentAddressMethod caMethod, HashType hashType, const StorePathSet &references, RepairFlag repair)
Definition remote-store.cc:413
kj::Promise< Result< std::map< std::string, std::optional< StorePath > > > > queryPartialDerivationOutputMap(const StorePath &path, Store *evalStore=nullptr) override
Definition remote-store.cc:359
kj::Promise< Result< std::vector< KeyedBuildResult > > > buildPathsWithResults(const std::vector< DerivedPath > &paths, BuildMode buildMode, std::shared_ptr< Store > evalStore) override
Definition remote-store.cc:715
kj::Promise< Result< StorePathSet > > queryValidDerivers(const StorePath &path) override
Definition remote-store.cc:332
kj::Promise< Result< StorePathSet > > queryDerivationOutputs(const StorePath &path) override
Definition remote-store.cc:343
kj::Promise< Result< void > > collectGarbage(const GCOptions &options, GCResults &results) override
Definition remote-store.cc:870
kj::Promise< Result< std::optional< StorePath > > > queryPathFromHashPart(const std::string &hashPart) override
Definition remote-store.cc:400
Definition config.hh:310
Definition path.hh:21
void unsupported(const std::string &op)
Definition store-api.hh:951
std::vector< std::pair< ValidPathInfo, std::function< kj::Promise< Result< box_ptr< AsyncInputStream > > >()> > > PathsSource
Definition store-api.hh:542
FileIngestionMethod
Definition content-address.hh:38
@ Recursive
Definition content-address.hh:47
Definition logging.hh:185
Definition derivations.hh:274
Definition content-address.hh:65
Definition realisation.hh:24
Definition serialise.hh:124
Definition serialise.hh:156
Definition gc-store.hh:22
Definition gc-store.hh:73
Definition gc-store.hh:121
Definition log-store.hh:10
Definition realisation.hh:49
Definition remote-store.hh:26
Definition remote-store-connection.hh:102
Definition remote-store-connection.hh:18
Definition path-info.hh:83