Nix 2.26.3
Nix, the purely functional 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
7#include "store-api.hh"
8#include "gc-store.hh"
9#include "log-store.hh"
10
11
12namespace nix {
13
14
15class Pipe;
16class Pid;
17struct FdSink;
18struct FdSource;
19template<typename T> class Pool;
20
21struct RemoteStoreConfig : virtual StoreConfig
22{
23 using StoreConfig::StoreConfig;
24
25 const Setting<int> maxConnections{this, 1, "max-connections",
26 "Maximum number of concurrent connections to the Nix daemon."};
27
28 const Setting<unsigned int> maxConnectionAge{this,
29 std::numeric_limits<unsigned int>::max(),
30 "max-connection-age",
31 "Maximum age of a connection before it is closed."};
32};
33
38class RemoteStore : public virtual RemoteStoreConfig,
39 public virtual Store,
40 public virtual GcStore,
41 public virtual LogStore
42{
43public:
44
45 RemoteStore(const Params & params);
46
47 /* Implementations of abstract store API methods. */
48
49 bool isValidPathUncached(const StorePath & path) override;
50
51 StorePathSet queryValidPaths(const StorePathSet & paths,
52 SubstituteFlag maybeSubstitute = NoSubstitute) override;
53
54 StorePathSet queryAllValidPaths() override;
55
56 void queryPathInfoUncached(const StorePath & path,
57 Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
58
59 void queryReferrers(const StorePath & path, StorePathSet & referrers) override;
60
61 StorePathSet queryValidDerivers(const StorePath & path) override;
62
63 StorePathSet queryDerivationOutputs(const StorePath & path) override;
64
65 std::map<std::string, std::optional<StorePath>> queryPartialDerivationOutputMap(const StorePath & path, Store * evalStore = nullptr) override;
66 std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override;
67
68 StorePathSet querySubstitutablePaths(const StorePathSet & paths) override;
69
70 void querySubstitutablePathInfos(const StorePathCAMap & paths,
71 SubstitutablePathInfos & infos) override;
72
77 Source & dump,
78 std::string_view name,
79 ContentAddressMethod caMethod,
80 HashAlgorithm hashAlgo,
81 const StorePathSet & references,
82 RepairFlag repair);
83
88 Source & dump,
89 std::string_view name,
92 HashAlgorithm hashAlgo = HashAlgorithm::SHA256,
93 const StorePathSet & references = StorePathSet(),
94 RepairFlag repair = NoRepair) override;
95
96 void addToStore(const ValidPathInfo & info, Source & nar,
97 RepairFlag repair, CheckSigsFlag checkSigs) override;
98
100 Source & source,
101 RepairFlag repair,
102 CheckSigsFlag checkSigs) override;
103
105 PathsSource && pathsToCopy,
106 Activity & act,
107 RepairFlag repair,
108 CheckSigsFlag checkSigs) override;
109
110 void registerDrvOutput(const Realisation & info) override;
111
112 void queryRealisationUncached(const DrvOutput &,
113 Callback<std::shared_ptr<const Realisation>> callback) noexcept override;
114
115 void buildPaths(const std::vector<DerivedPath> & paths, BuildMode buildMode, std::shared_ptr<Store> evalStore) override;
116
117 std::vector<KeyedBuildResult> buildPathsWithResults(
118 const std::vector<DerivedPath> & paths,
119 BuildMode buildMode,
120 std::shared_ptr<Store> evalStore) override;
121
122 BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
123 BuildMode buildMode) override;
124
125 void ensurePath(const StorePath & path) override;
126
127 void addTempRoot(const StorePath & path) override;
128
129 Roots findRoots(bool censor) override;
130
131 void collectGarbage(const GCOptions & options, GCResults & results) override;
132
133 void optimiseStore() override;
134
135 bool verifyStore(bool checkContents, RepairFlag repair) override;
136
145 void repairPath(const StorePath & path) override
146 { unsupported("repairPath"); }
147
148 void addSignatures(const StorePath & storePath, const StringSet & sigs) override;
149
150 void queryMissing(const std::vector<DerivedPath> & targets,
151 StorePathSet & willBuild, StorePathSet & willSubstitute, StorePathSet & unknown,
152 uint64_t & downloadSize, uint64_t & narSize) override;
153
154 void addBuildLog(const StorePath & drvPath, std::string_view log) override;
155
156 std::optional<std::string> getVersion() override;
157
158 void connect() override;
159
160 unsigned int getProtocol() override;
161
162 std::optional<TrustedFlag> isTrustedClient() override;
163
164 void flushBadConnections();
165
166 struct Connection;
167
168 ref<Connection> openConnectionWrapper();
169
170protected:
171
172 virtual ref<Connection> openConnection() = 0;
173
174 void initConnection(Connection & conn);
175
176 ref<Pool<Connection>> connections;
177
178 virtual void setOptions(Connection & conn);
179
180 void setOptions() override;
181
182 struct ConnectionHandle;
183
184 ConnectionHandle getConnection();
185
186 friend struct ConnectionHandle;
187
188 virtual ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override;
189
190 virtual void narFromPath(const StorePath & path, Sink & sink) override;
191
192private:
193
194 std::atomic_bool failed{false};
195
196 void copyDrvsFromEvalStore(
197 const std::vector<DerivedPath> & paths,
198 std::shared_ptr<Store> evalStore);
199};
200
201}
Definition callback.hh:17
Definition processes.hh:28
Definition file-descriptor.hh:181
Definition pool.hh:34
StorePathSet queryValidDerivers(const StorePath &path) override
Definition remote-store.cc:301
void registerDrvOutput(const Realisation &info) override
Definition remote-store.cc:591
virtual void narFromPath(const StorePath &path, Sink &sink) override
Definition remote-store.cc:926
BuildResult buildDerivation(const StorePath &drvPath, const BasicDerivation &drv, BuildMode buildMode) override
Definition remote-store.cc:764
StorePathSet querySubstitutablePaths(const StorePathSet &paths) override
Definition remote-store.cc:204
void addSignatures(const StorePath &storePath, const StringSet &sigs) override
Definition remote-store.cc:849
StorePath addToStoreFromDump(Source &dump, std::string_view name, FileSerialisationMethod dumpMethod=FileSerialisationMethod::NixArchive, ContentAddressMethod hashMethod=FileIngestionMethod::NixArchive, HashAlgorithm hashAlgo=HashAlgorithm::SHA256, const StorePathSet &references=StorePathSet(), RepairFlag repair=NoRepair) override
Definition remote-store.cc:459
void addTempRoot(const StorePath &path) override
Definition remote-store.cc:783
void optimiseStore() override
Definition remote-store.cc:831
unsigned int getProtocol() override
Definition remote-store.cc:909
ref< const ValidPathInfo > addCAToStore(Source &dump, std::string_view name, ContentAddressMethod caMethod, HashAlgorithm hashAlgo, const StorePathSet &references, RepairFlag repair)
Definition remote-store.cc:366
StorePathSet queryValidPaths(const StorePathSet &paths, SubstituteFlag maybeSubstitute=NoSubstitute) override
Definition remote-store.cc:181
void buildPaths(const std::vector< DerivedPath > &paths, BuildMode buildMode, std::shared_ptr< Store > evalStore) override
Definition remote-store.cc:661
void repairPath(const StorePath &path) override
Definition remote-store.hh:145
void ensurePath(const StorePath &path) override
Definition remote-store.cc:774
void setOptions() override
Definition remote-store.cc:167
StorePathSet queryDerivationOutputs(const StorePath &path) override
Definition remote-store.cc:310
std::optional< TrustedFlag > isTrustedClient() override
Definition remote-store.cc:915
void queryMissing(const std::vector< DerivedPath > &targets, StorePathSet &willBuild, StorePathSet &willSubstitute, StorePathSet &unknown, uint64_t &downloadSize, uint64_t &narSize) override
Definition remote-store.cc:858
void collectGarbage(const GCOptions &options, GCResults &results) override
Definition remote-store.cc:806
void querySubstitutablePathInfos(const StorePathCAMap &paths, SubstitutablePathInfos &infos) override
Definition remote-store.cc:224
std::map< std::string, std::optional< StorePath > > queryPartialDerivationOutputMap(const StorePath &path, Store *evalStore=nullptr) override
Definition remote-store.cc:322
void queryReferrers(const StorePath &path, StorePathSet &referrers) override
Definition remote-store.cc:290
void addToStore(const ValidPathInfo &info, Source &nar, RepairFlag repair, CheckSigsFlag checkSigs) override
Definition remote-store.cc:489
StorePathSet queryAllValidPaths() override
Definition remote-store.cc:195
void addMultipleToStore(Source &source, RepairFlag repair, CheckSigsFlag checkSigs) override
Definition remote-store.cc:572
std::optional< StorePath > queryPathFromHashPart(const std::string &hashPart) override
Definition remote-store.cc:355
virtual ref< SourceAccessor > getFSAccessor(bool requireValidPath=true) override
Definition remote-store.cc:934
bool verifyStore(bool checkContents, RepairFlag repair) override
Definition remote-store.cc:840
void connect() override
Definition remote-store.cc:903
Roots findRoots(bool censor) override
Definition remote-store.cc:790
std::vector< KeyedBuildResult > buildPathsWithResults(const std::vector< DerivedPath > &paths, BuildMode buildMode, std::shared_ptr< Store > evalStore) override
Definition remote-store.cc:680
Definition config.hh:320
Definition path.hh:27
std::vector< std::pair< ValidPathInfo, std::unique_ptr< Source > > > PathsSource
Definition store-api.hh:417
void unsupported(const std::string &op)
Definition store-api.hh:786
Definition ref.hh:15
FileSerialisationMethod
Definition file-content-address.hh:20
@ NixArchive
Definition file-content-address.hh:36
@ NixArchive
Definition file-content-address.hh:114
const Activity & act
Definition lexer.l:2371
RepairFlag repair
Definition lexer.l:7173
Definition logging.hh:137
Definition derivations.hh:285
Definition build-result.hh:14
Definition content-address.hh:31
Definition realisation.hh:24
Definition serialise.hh:125
Definition serialise.hh:157
Definition gc-store.hh:15
Definition gc-store.hh:60
Definition gc-store.hh:102
Definition log-store.hh:10
Definition realisation.hh:49
Definition remote-store.hh:22
Definition serialise.hh:20
Definition serialise.hh:68
virtual const std::string name()=0
Definition path-info.hh:130