Nix 2.26.3
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
4#include "signature/local-keys.hh"
5#include "store-api.hh"
6#include "log-store.hh"
7
8#include "pool.hh"
9
10#include <atomic>
11
12namespace nix {
13
14struct NarInfo;
15
16struct BinaryCacheStoreConfig : virtual StoreConfig
17{
18 using StoreConfig::StoreConfig;
19
20 const Setting<std::string> compression{this, "xz", "compression",
21 "NAR compression method (`xz`, `bzip2`, `gzip`, `zstd`, or `none`)."};
22
23 const Setting<bool> writeNARListing{this, false, "write-nar-listing",
24 "Whether to write a JSON file that lists the files in each NAR."};
25
26 const Setting<bool> writeDebugInfo{this, false, "index-debug-info",
27 R"(
28 Whether to index DWARF debug info files by build ID. This allows [`dwarffs`](https://github.com/edolstra/dwarffs) to
29 fetch debug info on demand
30 )"};
31
32 const Setting<Path> secretKeyFile{this, "", "secret-key",
33 "Path to the secret key used to sign the binary cache."};
34
35 const Setting<Path> localNarCache{this, "", "local-nar-cache",
36 "Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`."};
37
38 const Setting<bool> parallelCompression{this, false, "parallel-compression",
39 "Enable multi-threaded compression of NARs. This is currently only available for `xz` and `zstd`."};
40
41 const Setting<int> compressionLevel{this, -1, "compression-level",
42 R"(
43 The *preset level* to be used when compressing NARs.
44 The meaning and accepted values depend on the compression method selected.
45 `-1` specifies that the default compression level should be used.
46 )"};
47};
48
49
54class BinaryCacheStore : public virtual BinaryCacheStoreConfig,
55 public virtual Store,
56 public virtual LogStore
57{
58
59private:
60 std::unique_ptr<Signer> signer;
61
62protected:
63
64 // The prefix under which realisation infos will be stored
65 const std::string realisationsPrefix = "realisations";
66
67 const std::string cacheInfoFile = "nix-cache-info";
68
69 BinaryCacheStore(const Params & params);
70
71public:
72
73 virtual bool fileExists(const std::string & path) = 0;
74
75 virtual void upsertFile(const std::string & path,
76 std::shared_ptr<std::basic_iostream<char>> istream,
77 const std::string & mimeType) = 0;
78
79 void upsertFile(const std::string & path,
80 // FIXME: use std::string_view
81 std::string && data,
82 const std::string & mimeType);
83
87 virtual void getFile(const std::string & path, Sink & sink);
88
93 virtual std::optional<std::string> getNixCacheInfo();
94
99 virtual void getFile(
100 const std::string & path,
101 Callback<std::optional<std::string>> callback) noexcept;
102
103 std::optional<std::string> getFile(const std::string & path);
104
105public:
106
107 virtual void init() override;
108
109private:
110
111 std::string narMagic;
112
113 std::string narInfoFileFor(const StorePath & storePath);
114
115 void writeNarInfo(ref<NarInfo> narInfo);
116
117 ref<const ValidPathInfo> addToStoreCommon(
118 Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs,
119 std::function<ValidPathInfo(HashResult)> mkInfo);
120
121public:
122
123 bool isValidPathUncached(const StorePath & path) override;
124
125 void queryPathInfoUncached(const StorePath & path,
126 Callback<std::shared_ptr<const ValidPathInfo>> callback) noexcept override;
127
128 std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override;
129
130 void addToStore(const ValidPathInfo & info, Source & narSource,
131 RepairFlag repair, CheckSigsFlag checkSigs) override;
132
134 Source & dump,
135 std::string_view name,
136 FileSerialisationMethod dumpMethod,
137 ContentAddressMethod hashMethod,
138 HashAlgorithm hashAlgo,
139 const StorePathSet & references,
140 RepairFlag repair) override;
141
143 std::string_view name,
144 const SourcePath & path,
146 HashAlgorithm hashAlgo,
147 const StorePathSet & references,
148 PathFilter & filter,
149 RepairFlag repair) override;
150
151 void registerDrvOutput(const Realisation & info) override;
152
153 void queryRealisationUncached(const DrvOutput &,
154 Callback<std::shared_ptr<const Realisation>> callback) noexcept override;
155
156 void narFromPath(const StorePath & path, Sink & sink) override;
157
158 ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override;
159
160 void addSignatures(const StorePath & storePath, const StringSet & sigs) override;
161
162 std::optional<std::string> getBuildLogExact(const StorePath & path) override;
163
164 void addBuildLog(const StorePath & drvPath, std::string_view log) override;
165
166};
167
168MakeError(NoSuchBinaryCacheFile, Error);
169
170}
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:301
std::optional< StorePath > queryPathFromHashPart(const std::string &hashPart) override
Definition binary-cache-store.cc:382
ref< SourceAccessor > getFSAccessor(bool requireValidPath=true) override
Definition binary-cache-store.cc:516
void addSignatures(const StorePath &storePath, const StringSet &sigs) override
Definition binary-cache-store.cc:521
void narFromPath(const StorePath &path, Sink &sink) override
Definition binary-cache-store.cc:393
void registerDrvOutput(const Realisation &info) override
Definition binary-cache-store.cc:509
virtual void init() override
Definition binary-cache-store.cc:40
virtual void getFile(const std::string &path, Sink &sink)
Definition binary-cache-store.cc:84
virtual std::optional< std::string > getNixCacheInfo()
Definition binary-cache-store.cc:64
void addToStore(const ValidPathInfo &info, Source &narSource, RepairFlag repair, CheckSigsFlag checkSigs) override
Definition binary-cache-store.cc:283
Definition callback.hh:17
Definition config.hh:320
Definition path.hh:27
Definition ref.hh:15
FileSerialisationMethod
Definition file-content-address.hh:20
std::function< bool(const Path &path)> PathFilter
Definition file-system.hh:365
std::shared_ptr< std::basic_istream< char > > istream
Definition lexer.l:3574
std::variant< std::string, std::string_view > data
Definition lexer.l:177
RepairFlag repair
Definition lexer.l:7173
std::pair< Hash, uint64_t > HashResult
Definition hash.hh:174
Definition binary-cache-store.hh:17
Definition content-address.hh:31
Definition realisation.hh:24
Definition log-store.hh:10
Definition nar-info.hh:13
Definition realisation.hh:49
Definition serialise.hh:20
Definition source-path.hh:22
Definition serialise.hh:68
virtual const std::string name()=0
Definition path-info.hh:130