Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
binary-cache-store.hh
Go to the documentation of this file.
1#pragma once
3
7
8#include "nix/util/pool.hh"
9
10#include <atomic>
11
12namespace nix {
13
14struct NarInfo;
16
17struct BinaryCacheStoreConfig : virtual StoreConfig
18{
19private:
20 void anchor() override;
21
22public:
23 BinaryCacheStoreConfig(const Params & params)
24 : StoreConfig(params, FilePathType::Unix)
25 {
26 }
27
28 Setting<CompressionAlgo> compression{
29 this,
30 CompressionAlgo::xz,
31 "compression",
32 R"(
33 NAR compression method. One of: `xz`, `bzip2`, `gzip`, `zstd`, `none`, `br`, `compress`, `grzip`, `lrzip`, `lz4`, `lzip`, `lzma` or `lzop`.
34 To use a particular compression method Nix has to be built with a version of libarchive that natively supports that compression algorithm.
35 )"};
36
37 Setting<bool> writeNARListing{
38 this, false, "write-nar-listing", "Whether to write a JSON file that lists the files in each NAR."};
39
40 Setting<bool> writeDebugInfo{
41 this,
42 false,
43 "index-debug-info",
44 R"(
45 Whether to index DWARF debug info files by build ID. This allows [`dwarffs`](https://github.com/edolstra/dwarffs) to
46 fetch debug info on demand
47 )"};
48
50 this, std::nullopt, "secret-key", "Path to the secret key used to sign the binary cache."};
51
52 Setting<std::string> secretKeyFiles{
53 this, "", "secret-keys", "List of comma-separated paths to the secret keys used to sign the binary cache."};
54
56 this,
57 std::nullopt,
58 "local-nar-cache",
59 "Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`."};
60
61 Setting<bool> parallelCompression{
62 this,
63 false,
64 "parallel-compression",
65 R"(
66 Enable multi-threaded compression of NARs. This is currently only available for `xz` and `zstd`.
67
68 If not set explicitly, defaults to `true` when `compression` is `zstd` and `false` otherwise.
69 )"};
70
71 Setting<int> compressionLevel{
72 this,
73 -1,
74 "compression-level",
75 R"(
76 The *preset level* to be used when compressing NARs.
77 The meaning and accepted values depend on the compression method selected.
78 `-1` specifies that the default compression level should be used.
79 )"};
80};
81
86struct alignas(8) /* Work around ASAN failures on i686-linux. */
87 BinaryCacheStore : virtual Store,
88 virtual LogStore
89{
90 using Config = BinaryCacheStoreConfig;
91
96 Config & config;
97
98private:
99 void anchor() override;
100
101 std::vector<std::unique_ptr<Signer>> signers;
102
103protected:
104
118 constexpr static const std::string realisationsPrefix = "build-trace-v2";
119
120 constexpr static const std::string cacheInfoFile = "nix-cache-info";
121
122 BinaryCacheStore(Config &);
123
129 std::string makeRealisationPath(const DrvOutput & id);
130
131public:
132
133 virtual bool fileExists(const std::string & path) = 0;
134
135 virtual void upsertFile(
136 const std::string & path, RestartableSource & source, const std::string & mimeType, uint64_t sizeHint) = 0;
137
138 void upsertFile(
139 const std::string & path,
140 // FIXME: use std::string_view
141 std::string && data,
142 const std::string & mimeType,
143 uint64_t sizeHint);
144
145 void upsertFile(
146 const std::string & path,
147 // FIXME: use std::string_view
148 std::string && data,
149 const std::string & mimeType)
150 {
151 auto size = data.size();
152 upsertFile(path, std::move(data), mimeType, size);
153 }
154
158 virtual void getFile(const std::string & path, Sink & sink);
159
164 virtual std::optional<std::string> getNixCacheInfo();
165
170 virtual void getFile(const std::string & path, Callback<std::optional<std::string>> callback) noexcept;
171
172 std::optional<std::string> getFile(const std::string & path);
173
174public:
175
176 virtual void init() override;
177
178private:
179
180 std::string narMagic;
181
182 std::string narInfoFileFor(const StorePath & storePath);
183
184 void writeNarInfo(ref<NarInfo> narInfo);
185
193 ref<NarInfo> uploadData(Source & narSource, RepairFlag repair, fun<ValidPathInfo(HashResult)> mkInfo);
194
201 void uploadNarInfo(ref<NarInfo> narInfo);
202
203 ref<const ValidPathInfo> addToStoreCommon(
204 Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs, fun<ValidPathInfo(HashResult)> mkInfo);
205
209 ref<RemoteFSAccessor> getRemoteFSAccessor(bool requireValidPath = true);
210
211public:
212
213 bool isValidPathUncached(const StorePath & path) override;
214
215 void queryPathInfoUncached(
216 const StorePath & path, Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
217
218 std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override;
219
220 void
221 addToStore(const ValidPathInfo & info, Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs) override;
222
223 void
224 addMultipleToStore(PathsSource && pathsToCopy, Activity & act, RepairFlag repair, CheckSigsFlag checkSigs) override;
225
227 Source & dump,
228 std::string_view name,
229 FileSerialisationMethod dumpMethod,
230 ContentAddressMethod hashMethod,
231 HashAlgorithm hashAlgo,
232 const StorePathSet & references,
233 RepairFlag repair) override;
234
236 std::string_view name,
237 const SourcePath & path,
239 HashAlgorithm hashAlgo,
240 const StorePathSet & references,
241 PathFilter & filter,
242 RepairFlag repair) override;
243
244 void registerDrvOutputUnchecked(const Realisation & info) override;
245
246 void queryRealisationUncached(
247 const DrvOutput &, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override;
248
249 void narFromPath(const StorePath & path, Sink & sink) override;
250
251 ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override;
252
253 std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath &, bool requireValidPath = true) override;
254
255 void addSignatures(const StorePath & storePath, const std::set<Signature> & sigs) override;
256
257 std::optional<std::string> getBuildLogExact(const StorePath & path) override;
258
259 void addBuildLog(const StorePath & drvPath, std::string_view log) override;
260};
261
262MakeError(NoSuchBinaryCacheFile, Error);
263
264} // namespace nix
Definition callback.hh:19
Definition remote-fs-accessor.hh:12
Definition serialise.hh:183
Definition configuration.hh:476
Definition path.hh:33
std::vector< std::pair< ValidPathInfo, std::unique_ptr< Source > > > PathsSource
Definition store-api.hh:680
Definition fun.hh:19
Definition ref.hh:58
FileSerialisationMethod
Definition file-content-address.hh:20
fun< bool(const std::string &path)> PathFilter
Definition file-system.hh:494
Definition logging.hh:221
Definition binary-cache-store.hh:18
Config & config
Definition binary-cache-store.hh:96
StorePath addToStoreFromDump(Source &dump, std::string_view name, FileSerialisationMethod dumpMethod, ContentAddressMethod hashMethod, HashAlgorithm hashAlgo, const StorePathSet &references, RepairFlag repair) override
Definition binary-cache-store.cc:451
void registerDrvOutputUnchecked(const Realisation &info) override
Definition binary-cache-store.cc:682
void addMultipleToStore(PathsSource &&pathsToCopy, Activity &act, RepairFlag repair, CheckSigsFlag checkSigs) override
Definition binary-cache-store.cc:320
std::optional< StorePath > queryPathFromHashPart(const std::string &hashPart) override
Definition binary-cache-store.cc:534
ref< SourceAccessor > getFSAccessor(bool requireValidPath=true) override
Definition binary-cache-store.cc:697
void addSignatures(const StorePath &storePath, const std::set< Signature > &sigs) override
Definition binary-cache-store.cc:707
void narFromPath(const StorePath &path, Sink &sink) override
Definition binary-cache-store.cc:545
std::string makeRealisationPath(const DrvOutput &id)
Definition binary-cache-store.cc:644
virtual void init() override
Definition binary-cache-store.cc:53
static constexpr const std::string realisationsPrefix
Definition binary-cache-store.hh:118
virtual void getFile(const std::string &path, Sink &sink)
Definition binary-cache-store.cc:102
virtual std::optional< std::string > getNixCacheInfo()
Definition binary-cache-store.cc:81
void addToStore(const ValidPathInfo &info, Source &narSource, RepairFlag repair, CheckSigsFlag checkSigs) override
Definition binary-cache-store.cc:305
Definition content-address.hh:32
Definition realisation.hh:26
Definition hash.hh:174
Definition log-store.hh:9
Definition nar-info.hh:38
Definition realisation.hh:103
Definition serialise.hh:18
Definition source-path.hh:22
Definition serialise.hh:95
@ Unix
Definition store-api.hh:131
Definition path-info.hh:159